Dynamically Adding Content (URL Requests, the Loader Class, and addChild)
//Dynamically adding objects to the stage using the Loader Class and AddChild Method
//start with a URL Request to access files outside of Flash
var url:URLRequest = new URLRequest("images/photo1.jpg");
//Use the Loader Class to load those files into Flash
var loadRequest:Loader = new Loader();
loadRequest.load(url);
//Add to the display list
//addChild(loadRequest);
var myPhoto:MovieClip = new MovieClip();
addChild(myPhoto);
myPhoto.x = stage.stageWidth/2 -150;
myPhoto.y = stage.stageHeight/2 -150;
//Wait for loading to to COMPLETE before working with loaded content
loadRequest.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event) {
myPhoto.addChild(loadRequest.content);
myPhoto.alpha = 0;
fadeUp();
}
//Custom Function to Fade In Content
function fadeUp() {
myPhoto.addEventListener(Event.ENTER_FRAME, fadeMe);
function fadeMe(e:Event) {
myPhoto.alpha += .05;
if (myPhoto.alpha >= 1) {
myPhoto.removeEventListener(Event.ENTER_FRAME, fadeMe);
}
}
}