More Conditionals
Here is an example of the monster moving using the code below. You will see the x value keeps going up even after the monster has left the stage.
Excercise
Download monster.fla
Open the fla and on the actions layer type the following in the actions panel
var moveSpeed:uint = 5; // speed monster will move
var hitSide:Boolean = false;
stage.addEventListener(Event.ENTER_FRAME, moveMonster);
function moveMonster(event:Event):void{
monster.x +=moveSpeed;
}
The first line is a variable that controls the speed the alien moves across the stage. The second variable will be used later to see if the monster has reached the other end.
The event listener is then created and attached to the stage, the event is a enter frame and this will be called continously calling the function moveMonster. The movieclip with an instance name of monster then has its x position incremented by the value of the moveSpeed variable.
Control / Test Movie
Excercise
Using the code fom the lecture slides see if you can get the monster to move left and right across the stage.
