0

我有一个外部 swf 加载到主框架(URL 请求)中,当 swf 到达它的最后一帧时,我需要它来 UNLOAD 本身。我需要在 CHILD swf 上没有任何代码的情况下执行此操作,因为这是针对 iOS 应用程序的。任何人都可以帮忙吗?

//start button

start_button_aboriginal.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_3);

import fl.display.ProLoader;
var fl_ProLoader_3:ProLoader;

//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad_3:Boolean = true;

function fl_ClickToLoadUnloadSWF_3(event:MouseEvent):void
{
if(fl_ToLoad_3)
{
    fl_ProLoader_3 = new ProLoader();
    fl_ProLoader_3.load(new URLRequest("myths/myth_aboriginal.swf"));
    addChild(fl_ProLoader_3);
    fl_ProLoader_3.x = 114;
    fl_ProLoader_3.y = 41;
}
else
{
    fl_ProLoader_3.unload();
    removeChild(fl_ProLoader_3);
    fl_ProLoader_3 = null;
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_3 = !fl_ToLoad_3;

//here, I want to UNLOAD the external SWF when it is finished playing.

var totFrames:Number=childMC.totalFrames;
var curFrame:Number;

childMC.addEventListener(Event.ENTER_FRAME, remove);

    function remove(evt:Event):void {
    curFrame=childMC.currentFrame;
    if (totFrames==curFrame) {
        removeChild(childMC);
    }
}
4

1 回答 1

0

您需要在全局范围内声明 childMC 并分配加载程序内容。并且不要在函数内部声明函数!

像这样的东西不是 TESTET

import fl.display.Loader; // impoerts belong at the top

var fl_ProLoader_3:ProLoader; // then your global vars
var childMC:MovieClip; // instatiate childMC with global scope

start_button_aboriginal.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_3,false,0,false); // listener with weak refference

var fl_ToLoad_3:Boolean = true;

function fl_ClickToLoadUnloadSWF_3(event:MouseEvent):void
{
if(fl_ToLoad_3)
{
    fl_ProLoader_3 = new Loader();
    var url:URLRequest = new URLRequest("myths/myth_aboriginal.swf"); 
    var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null); // IOS needs this
        fl_ProLoader_3.load(url, loaderContext);
    fl_ProLoader_3.addEventListener(Event.COMPLETE, loadCompleteHandler,false,0,false);

}
else
{
    if(childMC){
            removeChild(childMC);
            childMC.unloadAndStop();
            childMC = null; 
    }

}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_3 = !fl_ToLoad_3;

}
function loadCompleteHandler(evt:Event):void
{
        childMC = evt.target.content as MovieClip;
        childMC.addEventListener(Event.ENTER_FRAME, remove);
        addChild(childMC);
        childMC.x = 114;
        childMC.y = 41;
}

function remove(evt:Event):void {
    var totFrames:Number=childMC.totalFrames;
    var curFrame:Number =childMC.currentFrame;;

    if (totFrames==curFrame) {
      childMC.removeEventListener(Event.ENTER_FRAME, remove);
      removeChild(childMC);
      childMC.unloadAndStop();
      childMC = null;
  }
}
于 2013-03-29T09:53:12.100 回答