You are on page 1of 9

Step 1.

For this tutorial, you'll need to download the image of a rock below, and then import (File >
Import > Import to Stage) it into Flash.

Step 2.
We only need the rock temporarily on stage, so it doesn't matter which layer you import it
on. Convert the rock into an MC (movieclip symbol) called 'asteroid'. Later on we'll be
using actionscript to attach this MC from the library onto the stage. To make this possible,
the MC needs to be given an 'identifier', to make Flash know that we want to do this and to
also make it unique. You can give the MC an identifier by checking 'Export for
Actionscript'. The identifier should automatically be named the same as the MC.

Step 3.
Go into the asteroid MC and then convert the rock image into another MC called 'rockMC'.
You don't need to give it an identifer.

as shown in image b) a) b) Step 5. we can create some instances of it to form an asteroid. To make the asteroid appear more random. but this time rotate it clockwise (modify > transform > rotate 90 CW) a) b) . Now that the rock is contained in an MC.Step 4. rotate the 2nd rockMc counter clockwise (modify > transform > rotate 90 CCW). Add another copy onto the layer 'rock 3'. So first of all create a new layer called 'rock 2' and drag another copy of rockMc from the libray onto this layer.

. this time rotating it counter clockwise again. In the previous part we formed an asteroid. which will be triggered when a missile from the ship hits it. using 4 instances of the rockMc. Add an 4th and final rockMc onto layer 'rock 4'. In this 2nd part we're going to animat the rock destructing.Step 6. a) b) Step 7.

. if they don't reach that far. on frame 40. so you may need to come back to this later. Step 9. Highlight frame 40.Step 8. of all 4 layers. away from its original position. Zoom out to 50% and move each rock. The rockMc's will need to move outside of the screen area. and then create a key frame (F6) for each of them.

The rocks should now move. Step 11. The rocks need to stay together. right click and choose 'Create Motion Tween'.Step 10. as you move the timeline play head from left to right. so we need to create a stop() action on frame 1. . Highligh a frame of all 4 layers. I've done so on a 5th layer called script. until the asteroid is hit.

so restart variable is set to 'true'. The code that hasn't been greyed out is new. with the eisting code grey out.Step 12. Step 13. and will be explained below. . Next we want to add some code for when bullets reached the top of the screen. which adds a bullet. go back to the main timeline and click on the 1st frame of the 'shot' layer. or if it hits the asteroid. Previously a moveBullets function had been created. We also need a way of knowing when the animation has reach frame 40. When the asteroid is hit. Step 14. but we need to create another stop() action at frame 40. where we'll be building ont he existing code. So now that we've create the animated asteroid. the animation will play. The moveBullets function is shown below. when the space bar is pressed. so that it doesn't play again.

Line 25: Since the current bullet. 'hit' is set to true. later on. Line 34: Now that the bullet has hit the asteroid. Line 33: b (the current bullet in the loop) is checked to see if it hits ob. Line 26: The top of the screen is 0 on the Y axis. When the whole of the bullet is outside of the screen we want to remove. in the array that's being looped through. is going to be referenced a number of times.30: If not (else) the bullet's MC is then removed from the stage and it's reference is removed from the array. so an IF statement is used to check to see if the bullet is above the point (-50 Y) at which it should be removed. It's been named 'ob' because we may want to use different objects. which will be the the instance name given to the asteroid later on. Line 28 . This will be when the asteroid has just been hit. to stop it from being . Line 32: A variable is used for when we don't want to check if the bullet is hitting the asteroid. it is assigned to the temporary variable 'b'. instead of an asteroid.

Line 46: The asteroid needs to appear randomly on the x axis. with the argument (o). so a function is created to do this. the name of the MC's identifier ("asteroid") will be entered as the argument like so: createObject("asteroid"). so that we then reference it indepedent of what the object is. When the function is called. the asteroid animation will play.checked. Line 44: A function to create an object. This will be useful for if a different object is used. Line 45: The asteroid will then be attached and assigned to the variable 'ob'. Line 36 . where all four rocks move away. to stop and resume collision detection Line 43: A variable to set the speed of the object (asteroid). Step 16. Line 49-50 : The object is given a new random X position to start from and placed at -40 on . Line 42: A hit variable to false.37: The bullet's MC is then removed from the stage and it's reference is removed from the array. Line 48: When the object ("asteroid") has reached the end of its exploding animation or when its moved to the bottom of the stage. Step 15. Line 35: If 'b' hits 'ob'. it needs to be "reset". since we will only have to change it when the function is called.

so that it's checked all the time. Step 17. Line 61-62: We also need to check if the asteroid has finished exploding. If is is then the object needs to be moved. The restart function also needs to be set back to false. in which case the asteroid is reset. the object is created Line 67: And the moveObject function is added to the onEnterFrame function. it's needs to go back to frame 1 so that's whole again. so that the resetObject function isn't called again. Line 53: Hit needs to be set back to false so that checking can resume.the Y axis. of the bullets hitting the asteroid. Step 18 Line 65: Lastly. Line 58-59: If it's not (else) then that's means it's reached beyond 250 and needs to be reset. . Line 55: Next a function is created to move the object (asteroid) Line 56-57: An IF statement is placed to check if the objects Y value is lower than 250 (the bottom of the stage). Line 51-52 : When the asteroid has reached the end of the exploding animation.