Shoot Game Part 3: Creating Multiple Targets on Stage

Tue, Oct 13, 2009

ActionScript

This movie requires Flash Player 9

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!

//The Shoot Game – Placing Multiple Targets on Stage
// 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();

Cartoonist Drawing Tutorials

Related Articles:

, , , , , , , , , , ,

Leave a Reply

You must be logged in to post a comment.

My name is Avraham Saltoun, and I live in Jerusalem, Middle East. I am currently on my mid  40's and I am a computer programming technician. Here you will find over one hundred quality video tutorials on Actionscript, and yes, I give online support for aspiring programmers, and pros as well, sharing screen on skype and delivering source code by email, click the button for live flash actionscript support now!

 
oDesk Certified Action Script Programmer
oDesk Certified Adobe Flash CS3 Designer
oDesk Certified Adobe Photoshop 6.0 Designer
Skype Me™!

$7.49 .Com! Score Savings Cartoon Smart Tutorials


839
Unique Visitors
Previous 30 Days
Powered By Google Analytics