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 Do you need more help? Ask now!
|
|
| Last Updated ( Friday, 28 March 2008 ) |