First open up a regular flash document 550 in width by 400 in height with a regular white background. Then draw a happy face(this is what we are going to shoot). Select the happy face and go to modify-->Convert to Symbol and convert it into a movie clip symbol.
Now name the symbol "face". Select the face symbol, and open the properties box. There will be a input box under a dropdown box that says "movie clip". This input box is the instance name. Put "face" there as well. Now select the face symbol and open up the actions box and type this code in:
onClipEvent(load)
{
function reset()
{
if(this._name=="face")
{
this._visible=false;
}
else
{
this._visible=true;
}
this.dead=0;
this.speed=random(4)+3;
this._x=600;
this._y=random(400);
}
this.reset();
}
onClipEvent(enterFrame)
{
this._x-=this.speed;
if(this._x<-40)
{
this.reset();
}
}
This is just some simple code to generate the face and make it move across the screen. The onClipEvent(load) code is what happens when the movie clip first loads and the onClipEvent(enterFrame) code is what happens on each successive frame entry(a usual game is about 20-30 frames per second).
There is a reset function in the load event. This resets the movie clip to where we want the face's starting point to be. In this reset function we tell it that if the clip's name is "face" then make the clip not visible, but if it isn't face, make it visible. We want to original face to be invisible so we do this, we will generate the actual enemies in the main timeline later. Then we set some initial properties for the face. We set dead=0 so to indicate that the face does not start out dead. We set the speed to a random number between 0 and 3 plus 3. We set the initial x position to 600(just a bit off the screen) and we set the initial y position to a random number between 0 and 399(somewhere within the screen). We reset immediately on load because we want our clip to have these properties right when they appear. The onClipEvent(enterFrame) code is easy, we just tell our clip to decrement its x position by the speed on each frame entry(this moves it from right to left across the screen). If the x position reaches less than -40 or falls off the screen, we reset the clip to its original position.
We hope the information helped you. If you have any questions
or comments, please don't hesitate to post them on the
Forums section Submit your Tutorial at Click Here