Ok, so I made some progress. If in the progress handler I do something
like...
if(event.bytesLoaded == event.bytesTotal)
{
var timer: Timer = new Timer(1000, 1);
timer.addEventListener(TimerEvent.TIMER, this.handleTimer);
timer.start();
}
I can the access the the lib in the timer handler. Hooray! :) Not sure
why the complete event never fires but I can work with this.
Paul Spitzer wrote:
> Hi All,
>
> Hoping someone can help me out here... I'm near the point of loosing my
> mind. I'm trying to do a simple load of a library SWF in order to use
> the classes within. Unfortunately it's not working. What I did was
> create a new library project, stuffed in a couple of classes, extracted
> the swf from the swc, and then created an ActionScript project in which
> I load the SWF.
>
> When I use the Loader object to load the SWF the complete event never
> fires. I see progress events and I see the bytesLoaded matching the
> bytesTotal but no complete event. When I use URLLoader the SWF loads up
> no problem but I can't seem to access any of the classes in the library
> SWF. Using getDefinitionByName throws an error. If instead of a library
> project I create and load an ActionScript project SWF it all works as
> expected. But only when I use a Loader to load the SWF. If I try to use
> URLoader it doesn't work. Again, getDefinitionByName throws an error. I
> could create the library as an ActionScript project but I'd really
> prefer not to have to, feels a little dirty.
>
> I was looking at the way the Flex framework works with RSLs and it
> appears it does exactly what I'm trying to do. That is,
> it loads a library swf making the classes available at runtime. I tried
> duplicating the code in mx.preloaders.Preloader but to no avail. I
> tested a Flex project with an RSL and after adding some debug code I
> found the complete event in the Preloader (RSLNode) fires without any
> issues. I don't understand what I'm doing wrong, or not doing, or what
> the framework is doing that I'm not. Here's my code, about as simple as
> it gets...
>
>
> public function LibLoader()
> {
> var loader: Loader = new Loader();
>
> loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
> handleProgress);
> loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> handleLoadComplete);
> loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
> handleLoadError);
>
> loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
> handleLoadError);
>
> var loaderContext: LoaderContext = new LoaderContext();
> loaderContext.applicationDomain = ApplicationDomain.currentDomain;
> loader.load(new URLRequest("TestLib.swf"), loaderContext);
> }
>
> private function handleProgress(event: ProgressEvent):void
> {
> trace("progress");
> }
>
> private function handleLoadComplete(event: Event):void
> {
> trace("complete");
> }
>
> private function handleLoadError(event: ErrorEvent):void
> {
> trace("error");
> }
>
>
> Any insight?
>
> Many thanks,
>
> Paul
>
>
>