I am attempting to use one SWF to load another, acting as a preloader. The loader works fine by itself. The content works fine by itself. When you have the loader load the content, the content.stage is null. How do I fix this?
I stole the preloading code from Senocular, because it was the clearest example I found. However, I still don’t comprehend what makes the content SWF appear on top of the loader. Where is the loaded content initialized? It appears to be done automatically.
package
{
import flash.display.MovieClip;
import flash.events.ProgressEvent;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.text.TextField;
import flash.net.URLRequest;
public class Preloader extends MovieClip
{
var request:URLRequest = new URLRequest("Flash Engine 2.swf");
var loader:Loader = new Loader();
public function Preloader():void
{
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(request);
}
function loadProgress(event:ProgressEvent):void
{
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
txtLoading.text = "Loading... " + percentLoaded + "%";
trace("Loading: "+percentLoaded+"%");
}
function loadComplete(event:Event):void
{
trace("Complete");
addChild(event.currentTarget.content);
}
}
Cheers.
(I literally had a nightmare about ActionScript this past Saturday.)