Question
How do I reference a MovieClip from a class
Hi. Trying to learn AS3 and having a hard time ; (
I'm working on a game. I have a Ship class that uses addChild to add a linked Bullet MovieClip to the stage. The Bullet MC is linked to the class below. I've got it working so it moves up the screen, but now I need to build a hitTest, however I cant get access to a movie clip I've placed on the stage, "enemyDisplay_mc". How do I reference this MC? In AS2 I would just do a _root.
Thanks!
package {
import flash.display.*;
import flash.events.Event;
//
public class Weapons extends MovieClip {
private var _thisWeaponMC:MovieClip;
private var _enemyHit:DisplayObject;
private var _speed:Number;
public function Weapons () {
this.addEventListener (Event.ADDED,Initialize);
}
//
private function Initialize (event:Event):void {
//trace ("Weapons");
_thisWeaponMC = MovieClip(this.parent.getChildByName(this.name));
trace ("_thisWeaponMC: " + _thisWeaponMC);
_thisParent = event.currentTarget.parent;
trace ("_thisParent: " + _thisParent);
_enemyHit = this.parent.getChildByName("enemyDisplay_mc");
trace ("_enemyHit: " + _enemyHit);
_speed=20;
this.addEventListener (Event.ENTER_FRAME,moveShip);
}
//
private function moveShip (event:Event):void {
this.y-= _speed;
}
}
}
I'm working on a game. I have a Ship class that uses addChild to add a linked Bullet MovieClip to the stage. The Bullet MC is linked to the class below. I've got it working so it moves up the screen, but now I need to build a hitTest, however I cant get access to a movie clip I've placed on the stage, "enemyDisplay_mc". How do I reference this MC? In AS2 I would just do a _root.
Thanks!
package {
import flash.display.*;
import flash.events.Event;
//
public class Weapons extends MovieClip {
private var _thisWeaponMC:MovieClip;
private var _enemyHit:DisplayObject;
private var _speed:Number;
public function Weapons () {
this.addEventListener (Event.ADDED,Initialize);
}
//
private function Initialize (event:Event):void {
//trace ("Weapons");
_thisWeaponMC = MovieClip(this.parent.getChildByName(this.name));
trace ("_thisWeaponMC: " + _thisWeaponMC);
_thisParent = event.currentTarget.parent;
trace ("_thisParent: " + _thisParent);
_enemyHit = this.parent.getChildByName("enemyDisplay_mc");
trace ("_enemyHit: " + _enemyHit);
_speed=20;
this.addEventListener (Event.ENTER_FRAME,moveShip);
}
//
private function moveShip (event:Event):void {
this.y-= _speed;
}
}
}