I don't know why it wouldn't be valid or corrupt but... something is weird. What I settled on is loading the SWF with URLLoader and then using loadBytes on the ByteArray. I still have to wait a half a second or so after calling loadBytes before the classes are available but at least the loading of the SWF is somewhat normal.
Alex Harui wrote: > > URLLoader loads the SWF as data and does not parse the SWF for its > classes. > > Sounds like you’re doing everything right, but I would verify the SWF > in the SWC to make sure it is valid. > > ------------------------------------------------------------------------ > > *From:* [email protected] [mailto:[EMAIL PROTECTED] > *On Behalf Of *Paul Spitzer > *Sent:* Friday, March 28, 2008 2:53 PM > *To:* [email protected] > *Subject:* [flexcoders] Runtime Class Loading > > 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 > > ------------------------------------ -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) <*> To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

