|
-
Controling Movie Clip Arrays
I'm trying to make it so that ever time a player clicks the Zombies house, then the town hall a new zombie is created, added to the Zombie1Array and then moves towards the town hall.
So far i can add new zombies to the stage and they start to move although if i add a zombie whilst another is still moving then the first zombie stops and the second zombie moves, so only the most recent zombie added moves. Any Ideas?
Here's the code, sorry for it being long I think it's all needed:
import flash.events.MouseEvent;
import flash.events.Event;
stop();
//when zombie house is clicked make the selected variable alternate between 1 and 0
Zombie1House_mc.addEventListener(MouseEvent.CLICK, ZombieHouse1Selected);
var House1Selected:int = 0;
function ZombieHouse1Selected(Event:MouseEvent):void
{
if (House1Selected == 0)
{
House1Selected = 1;
//adds house name to selected house array
ZombieHouseArray[1] = "Zombie1House";
Zombie1House_mc.gotoAndStop("Selected");
trace(ZombieHouseArray);
}
else if (House1Selected == 1)
{
House1Selected = 0;
ZombieHouseArray[1] = "";
// removes name from array
Zombie1House_mc.gotoAndStop("null");
trace(ZombieHouseArray);
}
}
// same as previous
Zombie2House_mc.addEventListener(MouseEvent.CLICK, ZombieHouse2Selected);
var House2Selected:int = 0;
function ZombieHouse2Selected(Event:MouseEvent):void
{
if (House2Selected == 0)
{
House2Selected = 1;
ZombieHouseArray[2] = "Zombie2House";
Zombie2House_mc.gotoAndStop("Selected");
trace(ZombieHouseArray);
}
else if (House2Selected == 1)
{
House2Selected = 0;
ZombieHouseArray[2] = "";
Zombie2House_mc.gotoAndStop("null");
trace(ZombieHouseArray);
}
}
TownHall1_mc.addEventListener(MouseEvent.CLICK, SelectTownHall1);
//variables for arrays
var Zombie1Array:Array = ["AddZombie To 1"];
var Zombie_mc:MovieClip;
var ZombieHouseArray:Array = ["ZHouses"];
var Zombie1Count = 0;
var DNA1 = 0;
var Zombie2Array:Array = ["Added Zombies To 2"];
var Zombie2Count = 0;
var DNA2 = 0;
//Adds zombie to stage, array, sets variables
function SelectTownHall1(Event:MouseEvent):void
{
if (ZombieHouseArray.indexOf("Zombie1House") == 1)
{
trace("Attack From ZHouse 1");
Zombie_mc = new Zombie();
Zombie1Count = Zombie1Count + 1;
Zombie_mc.instanceName = "Zombie" + Zombie1Count;
Zombie1Array[Zombie1Count] = "Zombie" + Zombie1Count;
Zombie_mc.x = Zombie1House_mc.x - Zombie_mc.width - 5;
Zombie_mc.y = Zombie1House_mc.y + Zombie_mc.height + 5;
addChild(Zombie_mc);
trace(Zombie1Array);
}
if (ZombieHouseArray.indexOf("Zombie2House") == 2)
{
trace("Attack From ZHouse 2");
Zombie_mc = new Zombie();
Zombie2Count = Zombie2Count + 1;
Zombie_mc.instanceName = "Zombie" + Zombie2Count;
Zombie2Array[Zombie2Count] = "Zombie" + Zombie2Count;
Zombie_mc.x = Zombie2House_mc.x - Zombie_mc.width - 5;
Zombie_mc.y = Zombie2House_mc.y + Zombie_mc.height + 5;
addChild(Zombie_mc);
trace(Zombie2Array);
}
}
//Moves the Zombies
addEventListener(Event.ENTER_FRAME, onload);
function onload(e:Event):void {
if (Zombie_mc.x > (TownHall1_mc.x + TownHall1_mc.width/2)){
Zombie_mc.x--;
}
if (Zombie_mc.y > (TownHall1_mc.y + TownHall1_mc.height/2)){
Zombie_mc.y--;
}
if (Zombie_mc.x < (TownHall1_mc.x + TownHall1_mc.width/2)){
Zombie_mc.x++;
}
if (Zombie_mc.y < (TownHall1_mc.y + TownHall1_mc.height/2)){
Zombie_mc.y++;
}
}
Thanks a lot
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|