Hello. I have a button in as3 that uses a URLRequest to open a swf file. The fla file that the swf belongs to has the following code:
troop1_btn.addEventListener(MouseEvent.CLICK, createTroop1);
function createTroop1(e:MouseEvent) {
var myTroop1:MovieClip = new Troop1(); //get it from the library and call it myTroop
addChild(myTroop1); //add it to the display/stage
myTroop1.x = 80; // position it or do whatever you want with it
myTroop1.y = 320;
}
Now back in my original file I want to be able to access the movie clip to make it move and make it lose health and eventually come off stage. This is what I have so far but note that when I use “troop1_mc” that really is the instance name I gave my MovieClip. But instead of calling “troop1_mc” to stage, Im calling the class Name Troop1.
play_btn.addEventListener(MouseEvent.CLICK, begin);
var infantry:Number = 2; // the speed at which object moves
var infantryHealth:Number = 100;
var castleHealth:Number = 1000;
function begin (yourEvent:Event):void {
var castleDamage:Number = Math.random() *10;
var castleDamageRounded= Math.round(castleDamage);
troop1_mc.x += infantry;
troop1_mc.addEventListener(Event.ENTER_FRAME, begin)
if (troop1_mc.x >= 380){
troop1_mc.removeEventListener(Event.ENTER_FRAME, begin)
}
setTimeout(causeDamage, 7500);
function causeDamage() {
infantryHealth -= castleDamageRounded;
if (infantryHealth >= -10){
trace(infantryHealth);
troop1_mc.removeEventListener(Event.ENTER_FRAME, begin)
}
removeChild(troop1_mc);
}
I thought it would be as easy as replacing “troop1_mc” with Troop1 or myTroop1 but its not.
Any ideas?