# MovieClip help

**URL:** https://forum.kirupa.com/t/movieclip-help/322607
**Category:** Uncategorized
**Created:** [May 26, 2011, 9:23pm UTC](https://forum.kirupa.com/t/movieclip-help/322607 "2011-05-26T21:23:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![robotronic](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@robotronic](https://forum.kirupa.com/u/robotronic)
#### Post date: [May 26, 2011, 9:23pm UTC](https://forum.kirupa.com/t/movieclip-help/322607/1 "2011-05-26T21:23:41Z")

</div>

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 &gt;= 380){
troop1_mc.removeEventListener(Event.ENTER_FRAME, begin)
} 

setTimeout(causeDamage, 7500);
function causeDamage() {
infantryHealth -= castleDamageRounded;
    
    if (infantryHealth &gt;= -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?
