Your Ad Here

A video tutorial showing how to create a basic game using Actionscript 3.

The first thing which we do is create two movieclips, one called player and one called bullet then we remove them from our stage by pressing the delete key on your keyboard.

Comment 1
var Player:player = new player(); This creates a new instance of the movieclip which we made called player.
Player.x = mouseX; This sets the X position of Player to the X position of the mouse.
Player.y = mouseY; This sets the Y position of Player to the Y position of the mouse.
addChild(Player); This adds the Player instance that we have just created to the stage.

Comment 2
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove); An event listener listens out for an event which has been defined within the paranthesis. Here when the mouse moves on the stage then the function mousemove is called.
stage.addEventListener(MouseEvent.MOUSE_DOWN, shoot); When the left mouse button is pressed then the shoot function is called.

Comment 3
function mousemove(e:MouseEvent):void{, This creates the function mousemove and looks for mouse events.
Player.x = mouseX; Update the Player X position to the mouses X when the mouse is moved.
Player.y = mouseY; Update the Player Y position to the mouses Y when the mouse is moved.
} Close the function.

Comment 4
function shoot(e:Event):void{ create a function called shoot.
var Bullet:bullet = new bullet(); This creates a new instance of the bullet movieclip.
Bullet.x = Player.x; The Bullet X position is set to the same as the Player X position.
Bullet.y = Player.y; The Bullet Y position is set to the same as the Player Y position.
addChild(Bullet); Add the instance Bullet to the stage.
Bullet.addEventListener(Event.ENTER_FRAME, moveBullet); Add an event listener to Bullet for when it enters the frame and when it does call the function moveBullet.
} Now we close the function.

Comment 5
function moveBullet(e:Event):void{ create a function called moveBullet.
e.target.y -= 5; When the function is called the targets Y position will be subract by 5 pixels every frame, this makes the movieclip move up. The target is the Bullet movieclip.
if(e.target.y <= -10){ If the Y of Bullet is less than or equal to minus 10 then the event listener will be removed and so will the movieclip.
e.target.removeEventListener(Event.ENTER_FRAME, moveBullet);
removeChild(MovieClip(e.target));
} Close the function

Thanks for watching the tutorial and reading through the notes. If there is anything that you don’t understand then please post a omment and I will try to explain your problem as best as I can.

GET YOUR AD ON EVERY PAGE FOR $10 a month!
Your Ad Here