How does the Timer Event Repeat count work? On this tutorial we place 10 moving targets on stage, but not at once, by creating a timer, an event listener, an interval and a repeat count.
CLICK HERE FOR COMPLETE CLASSIC GAMING CARTOON SMART TUTORIAL
HERE IS THE SOURCE CODE!
// solutions at say-web dot com
// FREE to USE, COPY and DISTRIBUTE
var cursor:MovieClip;
//this creates the movie clip
//we will place on stage
// Let’s declare a few variables
// to create 10 airplanes on stage
var airplanesIngame:uint; //This will define how many airplanes on stage
var airplaneMaker:Timer; //This event will call a function
var container_mc:MovieClip; // We will place all planes inside a movie clip
function initializeGame():void {
airplanesIngame = 10; //I will test if this is not too much
airplaneMaker = new Timer (1000, airplanesIngame);
//Timer will run 10 times 1000 miliseconds each (1 second)
container_mc = new MovieClip;
// let;s place the container on stage
addChild(container_mc);
airplaneMaker.addEventListener(TimerEvent.TIMER, createAirplanes);
// This event will call the function that creates airplanes
// and places them inside of the container
//Let’s start our timer
airplaneMaker.start();
//This will fire the timer that will repeat 1 second 10 times
cursor = new Cursor;
//Note that the class has
//Capital C on the name
//cursor with a small c is the moive clip
// name
addChild(cursor);
//this will place a cursor on stage
cursor.enabled = false;
// this will neutralize the cursor
Mouse.hide();
//This will hide our own mouse (cursor)
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);
// this functions fires when the mouse moves
// changes the cursor location
}
function dragCursor (event:MouseEvent):void{
cursor.x=this.mouseX;
cursor.y=this.mouseY;
// this will place the cursor on stage according
// to the mouse coordinates
}
function createAirplanes (event:TimerEvent):void {
var airplaneInstance :MovieClip;
airplaneInstance = new Airplane;
airplaneInstance.x = (Math.random()*stage.stageWidth)/3;
// We want the airplanes on the left side of the stage
airplaneInstance.y = Math.random()*stage.stageHeight;
container_mc.addChild(airplaneInstance);
}
initializeGame();




































Tue, Oct 13, 2009
ActionScript