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:

, , , , , , , , , , ,

2 Responses to “Shoot Game Part 3: Creating Multiple Targets on Stage”

  1. Marcus Says:

    I am so new to all this online, the more I read the more I realize there’s so much more for me to learn, thanks for the awesome post I will be back!

  2. Harold Says:

    I usually do not leave comments, but I thought this was a great post! WoW:)


Leave a Reply

Security Code:

AVA Trading Forex
WIX create a FREE website.
Try ACT! 2010 Today
Accept Credit Cards
UseNeXT Fast Downloads
For Free Stuff Click Here

Get Paid for Filling Surveys


Go Daddy $7.49.com sale 125x125 Huddle Collaboration
oDesk Certified Action Script Programmer oDesk Certified Adobe Flash CS3 Designer oDesk Certified Adobe Photoshop 6.0 Designer

Compare Web Hosting Services and Prices

web hosting - Web Hosting guide to popular hosts.

Twitter Followers