AS3 - Loader class problem tracing the swf (document class)
I am using the Loader class to load 3 external swfs:
- sharedTopics.swf (does not have a document class)
- fonts.swf (document class is FontManager)
- main.swf (document class is Main)
The same loader is used to load all 3 assets.
__assetLoader = new Loader();
var urlReq:URLRequest = new URLRequest(target.path);
__assetLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, this.preloadProgress);
__assetLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.assetCompleteHandler);
__assetLoader.contentLoaderInfo.addEventListener(Event.INIT, this.assetInitHandler);
__assetLoader.load(urlReq);
In the complete handler, I add the loader content to a movie clip then trace out a variable:
var swf:DisplayObject = __assetLoader.content;
Debug.doTrace("Shell:: assetCompleteHandler():: content " + swf);
__app.addChild(MovieClip(swf));
When the sharedTopics, fonts and main swfs (respectively) are loaded I get the following trace statements:
Shell:: assetInitHandler():: evt.currentTarget.content [object MovieClip]
Shell:: assetInitHandler():: evt.currentTa开发者_运维知识库rget.content [object FontManager]
Shell:: assetInitHandler():: evt.currentTarget.content [object Main__Preloader__]
I would expect that the last trace statement would look similar to '[object Main]' which would be the name of the document class however, instead the content is the loader. Any ideas as to why this is happening?
In a later function I try to call the init function of the Main class and get the following error:
Error #1069: Property init not found on classes.Main__Preloader__ and there is no default value.
I hope this is explained clearly.
Thanks in advance,
Mike
The culprate was the TLFTextField. By default, in CS5, the 'Library path' (found in ActionScript3.0 Settings > Library Path) items are set to be Runtime Shared Libraries and use a default preloader, so by changing the 'Default Linkage' to 'Merged into code' you do not have to worry about externally loading these libraries...
It looks like main.swf wasn't intended to be loaded indirectly as you're attempted to do. zeh has a point , Main could be a child of the SWF...
If this is the case (and it looks like it is), you should have a look at Main.as , find the instance of Main_Preloader and retrieve the url it is loading and load this instead... or try to simply bypass Main_Preloader or/and re-implement it within your AssetLoading class.
精彩评论