Create a new layer and name it Action. Select it, click on the first frame, press F9 or select Window > Actions to open the Actions panel.
After that, enter the following ActionScript code inside the Actions panel:
information_txt.text = "Use your arrow keys to move the balloon!";
var speed:Number = 4;
object_mc.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+speed;
} else if (Key.isDown(Key.LEFT)) {
this._x = this._x-speed;
}
if (Key.isDown(Key.UP)) {
this._y = this._y-speed;
} else if (Key.isDown(Key.DOWN)) {
this._y = this._y+speed;
}
};
Action Script explanation:
1.information_txt.text = "Use your arrow keys to move the balloon!";
1. Display instructions on the screen
2 .var speed:Number = 4;
2. Set the speed for the object
3. object_mc.onEnterFrame = function() {
3. Capture the onEnterFrame event of the object_mc movie clip
4. if (Key.isDown(Key.RIGHT)) {
this._x = this._x + speed;
} else if (Key.isDown(Key.LEFT)) {
this._x = this._x - speed;
}
4. Move horizontally if the RIGHT or LEFT arrow keys are pressed
5. if (Key.isDown(Key.UP)) {
this._y = this._y - speed;
} else if (Key.isDown(Key.DOWN)) {
this._y = this._y + speed;
}
};
5. Move vertically if the UP or DOWN arrow keys are pressed
We're done!
Test your Movie (Ctrl+Enter).
Full Tutorial