这是在FlashDevelop中创建的AS3项目。它针对Flash播放器10。 运行此代码时遇到一个令人不安的问题:
package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public class Main extends MovieClip
{
private var loader:Loader;
private var sprite:Sprite;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init); }
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingDone);
loader.load(new URLRequest('loadIn.swf')); // error occurs when loading this file.
//loadIn.swf is compiled with all the code in this file but with the loader-parts commented out...
// just a Adobe Flash created graphic, no problems loading this one
//loader.load(new URLRequest('waitingPopup.swf'));
//sprite = new Sprite();
//sprite.graphics.beginFill(0xFF0000);
//sprite.graphics.drawRect(0, 0, 490, 356);
//sprite.graphics.endFill();
//addChild(sprite);
}
private function loadingDone(e:Event):void {
trace(loader.contentLoaderInfo.contentType); // application/x-shockwave-flash
trace(loader.contentLoaderInfo.parentAllowsChild); // true
trace(loader.contentLoaderInfo.sameDomain); // true
trace(loader.contentLoaderInfo.swfVersion); // 10
trace(loader.contentLoaderInfo.content); // [Object Main]
//this is were everything goes south
addChild(e.target.content);
}
}
}
现在,我可以从调试窗口收集到的内容,当我尝试调用addChild()
- 方法时,swf重新启动自身并在循环中结束。输出窗口中显示的所有内容都是:
[SWF] C:\svn\Development\TestProject\bin\loadIn.swf - 1 797 bytes after decompression.
application/x-shockwave-flash
true
true
10
[object Main]
任何想法会产生如此奇怪的循环和错误?我一直在努力解决这个问题。可能是FlashDevelop中的某种设置或MXMLC编译器的参数?
感谢所有答案!
答案 0 :(得分:0)
如果在添加子项之前删除了LoadingDone侦听器,则可能会有所帮助。也许第二个加载的swf的COMPLETE事件冒泡到主剪辑并重新触发另一个负载:
private function loadingDone(e:Event):void {
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadingDone);
addChild(e.target.content);
}
1
答案 1 :(得分:0)
如果它们具有相同的名称且您无法或不想更改名称,请尝试在URLRequest的LoaderContext中使用新的applicationDomain加载该文件:http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/system/LoaderContext.html 这应该解决任何冲突。