Moving a flash object

« Galves adventure alternate ending | DeviantFlash Online Games Blog | Covert Front Walkthrough »

Moving an object in flash is easy, but it’s an essential part of learning flash and actionscript. So in this tutorial I will learn you how to move flash objects with the arrow keys. In this tutorial I only coded the right arrow, you must code the other arrows. You must paste the code in the movie clip you want to control. If you’re too lame to read the whole tutorial here’s the complete code. Just reading code can be more valuable than reading the whole tutorial, because in the end you must learn to understand the code not only what it does.:
onClipEvent (enterFrame) {
if(Key.isDown(Key.RIGHT))
{
this._x += 1;
}
}
To move an object over the x-axis you use:
this._x += 1;
1 is the speed, this._x is the position on the x-axis of the object where the action scrip is in and += is the operator for add.
To capture mouse input you use:
if(Key.isDown(Key.RIGHT))
{
this._x += 1;
}
Key.isDown(Key.RIGHT) checks if the right key is down. So if you change it to Key.LEFT it will check for the right key.

But before you can add this code to a symbol you have to put onClipEvent (enterFrame) { around it, it makes sure it will run every time the frame passes:
onClipEvent (enterFrame) {
if(Key.isDown(Key.RIGHT))
{
this._x += 1;
}
}



Comments
There are no comments for this post yet
Add your comment:


Similar posts
Most popular posts
© Copyright 2007 DeviantFlash.com, Inc. All Rights Reserved. Powered by WordPress