Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website.  Home Flash & Swish Flash Tutorials Space Shooter - Movie Clip and Movement
Your Ad Here

Space Shooter - Movie Clip and Movement

Browse Pages: 2  3  4  5  > >>

This is the first part of a series of Space Shooter tutorials. In this part we are going to learn the basics of Movie Clips and character movement.

First create a new document in Flash, click "File" > "New...", select "ActionScript 2.0" and click Ok.

Create a Movie Clip by right clicking your library tab and selecting "New Symbol...", make sure "Movie Clip" is selected and choose a name.

image 1

Flash will create and open the MC for editing, so just paste an image or draw a space ship with Flash's drawing tools.

After drawing your ship, get back to the main timeline by click on "Scene 1":

image 2

Now drag your MC from the library to the Stage, select it and give it an instance name.

image 3

I am going to name it "Ship". So "Ship" is how I am going to call this MC instance inside my code.

We just made our ship, so let's make it move.

Right click the first frame in your timeline and select "Actions". Type this:

this.onEnterFrame = function() { if (Key.isDown(Key.RIGHT)) { Ship._x += 10; } else if (Key.isDown(Key.LEFT)) { Ship._x -= 10; } else if (Key.isDown(Key.UP)) { Ship._y -= 10; } else if (Key.isDown(Key.DOWN)) { Ship._y += 10; } }

Press Ctrl + Enter and test it, use the arrow key to move your ship around.

Here is how this code works:

this.onEnterFrame = function() { ... }

This is a very simple event from flash; the code inside it will be executed every time flash enters this frame.

if (Key.isDown(Key.RIGHT)) { Ship._x += 10; //_x -= 10 would move the ship to the left. }

This check if the right key is pressed, then move the Ship 10 pixels to the right.

else if (Key.isDown(Key.Up)) { Ship._y -= 10; // _y += 10 would move the ship down. }

If the up arrow key is pressed, the ship will move up.

It's the same thing as before, but this time we added "else" before "if" because we don't want the ship to move in two directions at the same time.

In case you want the ship to move freely remove the "else" and try to move it.

We are done with movement! In the next tutorial we are going to make our ship fire bullets.



About the Author:

Webzo Studio is a web design company located in the United States. Webzo Studio was founded in August 2005. We are a small team of designers that just love our job. The love of doing what we do is what makes us not doing our job as a job, but as an enjoyment.
read more about this author

Author's URL: Webzo Studio
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
Browse Pages: 2  3  4  5  > >>
Share print this page subscribe to newsletter subscribe to rss

Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website. More Flash & Swish: Most Popular Materials | Fresh Materials | More Flash Tutorials at FlashPerfection.com

No comments yet...
Add comments to "Space Shooter - Movie Clip and Movement"

Captcha