Skip to content

Instantly share code, notes, and snippets.

@sfdesigner
Created August 22, 2011 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfdesigner/1163565 to your computer and use it in GitHub Desktop.
Save sfdesigner/1163565 to your computer and use it in GitHub Desktop.
Removing children Loader instances from inside a MovieClip
/*
- A MovieClip is instantiated on the stage. In this example it is called removeMe
- A Loader class is created that loads a resource. The Loader class instance is added to the display stack within the removeMe MovieClip instance
- Another MovieClip is instantiated on the stage. This example names it clickMe. This MovieClip has an event listener attached to it listening for MouseEvent.CLICK, which then executes a callback function removeLoader()
- The removeLoader() event callback removes the Loader class instance from the display stack within the removeMe MovieClip instance
/*
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
var myLoader:Loader = new Loader();
var myLoaderContent:URLRequest = new URLRequest("http://www.helpexamples.com/flash/images/image1.jpg");
myLoader.load(myLoaderContent);
var removeMe:RemoveMe = new RemoveMe();
stage.addChild(removeMe);
removeMe.x = 25;
removeMe.y = 25;
removeMe.addChild(myLoader);
var clickMe:ClickMe = new ClickMe();
clickMe.x = 475;
clickMe.y = 25;
clickMe.addEventListener(MouseEvent.CLICK, removeLoader);
stage.addChild(clickMe);
function removeLoader(e:MouseEvent):void
{
removeMe.removeChild(myLoader);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment