从sdcard as3 Android重新加载Swf文件

时间:2014-08-07 12:51:28

标签: android actionscript-3 air flash external

我正在开发一个Android应用程序,我希望从外部服务器下载swf文件,将它们保存到SD卡并稍后在应用程序中加载它们。下载工作正常,swf保存在应用程序目录中。这是我从sdcard加载swf的代码:

var myloader:Loader = new Loader();
var myhomeButton:btnHome = new btnHome();

addChild(myloader);

var swfFilePath:File = File.applicationStorageDirectory.resolvePath("Android/data/myswffile.swf"); 
var inFileStream:FileStream = new FileStream(); 
inFileStream.open(swfFilePath, FileMode.READ); 
var swfBytes:ByteArray = new ByteArray();
inFileStream.readBytes(swfBytes);
inFileStream.close();

var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loaderContext.allowCodeImport = true;
myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, mycompleteHandler);
myloader.loadBytes(swfBytes, loaderContext);

function mycompleteHandler(evt:Event):void
{
    myloader.contentLoaderInfo.removeEventListener(Event.COMPLETE, mycompleteHandler);
    addChild(myhomeButton);
    myhomeButton.height = _height * 0.08;
    myhomeButton.width = myhomeButton.height;
    myhomeButton.x = 10;
    myhomeButton.y = 10;
    myhomeButton.addEventListener(MouseEvent.CLICK, myexitfftn);
}

function myexitftn(evt:Event):void
{
    myloader.unloadAndStop(true);
    removeChild(myhomeButton);
    gotoAndStop(1, "SomeOtherFrame");
}

问题是当我单击退出按钮时swf卸载但是当我重新加载它时,它从加载的swf的第二帧开始,第三次从第三帧开始,依此类推......我哪里出错了或者什么是替代解决方案,请指导。

1 个答案:

答案 0 :(得分:0)

在退出时,addChild(myloader)处理程序Complete以及removeChildnull尝试,以便加载swf从内存中完全删除,如下所示:< / p>

function mycompleteHandler(evt:Event):void
{
    myloader.contentLoaderInfo.removeEventListener(Event.COMPLETE, mycompleteHandler);

    addChild(myloader);


    //... Rest of code remains same
}

function myexitftn(evt:Event):void
{
    myloader.unloadAndStop();
    removeChild(myloader);
    myloader = null;   

    removeChild(myhomeButton);
    gotoAndStop(1, "SomeOtherFrame");
}