Alright, so i am doing soem work in flashdevelop and im encountering a small problem when i try to remove a movieclip from within itself.
MainChar class
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class MainChar extends Body
{
public function MainChar()
{
this.addEventListener(Event.ADDED_TO_STAGE, staging);
}
private function staging(e:Event):void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
}
private function handleKeyDown(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case 90 :
addChild(new Anim(this));
break;
}
}
}
}
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class Body extends MovieClip
{
public var Name:String;
public var body:Sprite = new Sprite();
public function Body()
{
body.graphics.beginFill(Math.random()*0xffffff);
body.graphics.drawCircle(0, 0, 10);
body.graphics.endFill();
addChild(body);
}
}
}
this is what gets added from the MainChar class:
package
{
import flash.display.MovieClip;
import flash.events.Event;
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
[Embed (source = "library.swf", symbol = "Swing")]
public class Anim extends MovieClip
{
private var remover:MovieClip;
public function Anim(cest:MovieClip)
{
remover = cest;
addEventListener(Event.ENTER_FRAME, init);
}
private function init(e:Event):void
{
if (currentFrame == totalFrames)
{
remover.removeChild(this);
}
}
}
}
its throwing that null object reference error…:
TypeError: Error #1009: Cannot access a property or method of a null object reference.