Control the playhead of a MovieClip using ActionScript |
| Written by AnaS | |
1. Create a new Flash document 400x300 dimensions2. Create two new layers
Rename the layers actions, movie, button starting from the top (like in the picture below). 3. Draw a circle
In the first frame of the movie layer use the Oval Tool (O) from the Tools Panel to draw a circle about 40pxx40px (hold Shift key pressed to draw a perfect circle). Select none for Stroke Color and what do you wish for Fill Color. 4. Convert the circle to a MovieClip
Select the circle and choose Modify >> Convert to Symbol (F8). In the Convert to Symbol window that appear choose MovieClip as Type, give it a name of ballMC and choose also center for Registration point like in the following image: 5. Go to the Poperties panel and give it an instance name of ball_mc
6. Edit in Place
Now right-click on the ball_mc and choose Edit in Place or double-click it. You are in the Edit Mode for ballMC now. 7. Convert the ball to a MovieClipSelect the ball and choose again Modify >> Convert to Symbol (F8). In the Convert to Symbol window choose same options like above and give it a name of ball2MC. 8. Now we'll do some animation with the ballGo to in the first frame of the Layer1 and in the Properties panel choose Tween:Motion. Go to the frame 30 and right-click >> Insert Keyframe (F6). Go to the frame 60 too and repeat the step. 9. Change the position of the ballGo back to frame 30 and change the position on the ball whetever you wish, but having at least 100 pixels from the original position. 10. Insert a buttonNow click Scene 1. Go to the first frame of the button layer. Go to Window >> Common Libraries >> Buttons. Choose from here a what button you desire and drag it on the Stage. In the Properties panel give it an instance name of button_btn.
11. The ActionScript codeNow go to the first frame of the actios layer. Open the Actions panel (F9) and put this ActionScript code in:
// we use the contor variable to hold the state of the ball: 1 if it is stopped, 0 if the ball is playing
button_btn.onRelease=function(){ // if the ball MovieClip is stopped we use the play() method to make it move
} // if the ball MovieClip is playing we use the stop() method to stop it
12. Test the movieNow test the movie (Ctrl+Enter) and see the result. Hope it was helpful! You need to Register in order to download the FLA file.
written by tony , November 22, 2007
hi . am using actionscript for first time and trying to make a penalty shootout game! at the moment , i have managed to make the keeper move randomly, the ball chasing the mouseclick and used hit Test() to detect either the save of the keeper or the goal. however, how: (i) is it possible to place only 1 shot , and then reset the process of shooting , so the ball is set back to the kick spot? (ii)can I end the game after 10 ball shootings? (iii) make the game over after three non goals i would appreciate your help!!!! cheers
written by rajeev_irm , March 23, 2009
hi, iam rajeev i desperately want some help its about the speedometer i made a speedometer and and i made a needle i had made needle movie clip and i had animated it . the thing i want is using action script i want to make it animate when entering a specific value in the text field. if u want the file i can give it to u so please help me to sort this problem thx
written by Joseph Eriksson , August 02, 2009
Hi! What code do you put in the first frame instead of applying "gotoAndPlay" on a certain frame. Ex: On frame 10, I want the playhead to start over on frame 1, but I want to write all the code for it in frame 1 of the actions layer. I.e. Playhead control by CODE only in the action layer, frame 1. Thank you in advance!
written by Elizabeth Eliades , November 23, 2009
I use Flash CS4, Actionscript 3. I am having trouble with step 8. While in scene 1 ballMC, I selected the ball and converted it to a movie clip, which i called ball2MC. Then, while still in scene 1 ballMC, i clicked on the first frame of "Layer 1", and looked at the properties panel, but no where could I select Motion:Tween. I went back into scene 1 and right clicked on the ball and selected Create Motion Tween. Then I followed the rest of the steps as described. When I ran the program, the ball moves, but choppily. Why could I not select Motion:Tween in the properties panel of Layer 1 frame 1? Do you need more help? Ask now!
|
|
| Last Updated ( Friday, 28 March 2008 ) |