Hello, I am very new to actionscript 3 and have a question about loaders and removing children.
Basically, I want to create a loader that loads in a swf (no prob there) but I also have a button on the stage that should simply remove that loader object when I click it, and I’m not sure how to do that.
This is the code I have…
btn_removeLoader.addEventListener(MouseEvent.CLICK, removeLoader);
function removeLoader(event:MouseEvent):void {
removeChild(ldr);
}
function createLoader():void {
var ldr:Loader = new Loader();
var [url:String](http://www.kirupa.com/forum/String) = "cartoon3.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
addChild(ldr);
}
createLoader();
When I publish I get an error about unidentified property ‘ldr’. I’m not sure how to pass the removeLoader function the name or child index of the loader. How can I get that function to remove my loader, or am I going about this the wrong way?
btn_removeLoader.addEventListener(MouseEvent.CLICK, removeLoader);
function removeLoader(event:MouseEvent):void {
var moo = getChildByName("theloader");
removeChild(moo);
}
function createLoader():void {
var ldr:Loader = new Loader();
ldr.name = "theloader";
var url:String = "cartoon3.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
addChild(ldr);
}
createLoader();