动作脚本3.0的问题,我的SWF不卸载 [英] Action script 3.0 issue, my swf not unloading

查看:144
本文介绍了动作脚本3.0的问题,我的SWF不卸载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个小麻烦与闪存的iOS应用程序!我有一个启动按钮,它加载外部SWF。然后,我有不同的按钮,家,它应该做的三件事情:

  1. 卸载外部SWF
  2. 停止所有声音
  3. 回归第1帧

这一切似乎工作,但随后便出现了SWF从来没有卸载!我一直一遍又一遍的听到了。

 的框架// code如下... mythbutt_home


 停止();

// home键

mythbutt_home.addEventListener(MouseEvent.CLICK,fl_ClickToGoToAndStopAtFrame_4);

功能fl_ClickToGoToAndStopAtFrame_4(事件:MouseEvent)方法:无效
{
removeChild之(fl_ProLoader_3);

}
mythbutt_home.addEventListener(MouseEvent.CLICK,fl_ClickToStopAllSounds);

功能fl_ClickToStopAllSounds(事件:MouseEvent)方法:无效
{
SoundMixer.stopAll();
}

mythbutt_home.addEventListener(MouseEvent.CLICK,fl_ClickToGoToAndStopAtFrame_1);

功能fl_ClickToGoToAndStopAtFrame_1(事件:MouseEvent)方法:无效
{
gotoAndStop(1);
}


//启动按钮

start_button_aboriginal.addEventListener(MouseEvent.CLICK,fl_ClickToLoadUnloadSWF_3);

进口fl.display.ProLoader;
VAR fl_ProLoader_3:ProLoader;

//这个变量跟踪是否要加载或卸载的SWF
VAR fl_ToLoad_3:布尔=真;

功能fl_ClickToLoadUnloadSWF_3(事件:MouseEvent)方法:无效
{
如果(fl_ToLoad_3)
{
    fl_ProLoader_3 =新ProLoader();
    fl_ProLoader_3.load(新的URLRequest(神话/ myth_aboriginal.swf));
    的addChild(fl_ProLoader_3);
    fl_ProLoader_3.x = 114;
    fl_ProLoader_3.y = 41;
 }
 其他
 {
    fl_ProLoader_3.unload();
    removeChild之(fl_ProLoader_3);
    fl_ProLoader_3 = NULL;
}
//切换是否要加载或卸载的SWF
fl_ToLoad_3 = fl_ToLoad_3!;
}
 

解决方案

首先你不应该超过multible帧这样做。这将是最好使用外部.as文件。 要正确卸载瑞士法郎,你需要删除所有refrences到SWF本身和对象的SWF。这包括EventListeners的对,你应该使用弱REFFERENCE是这样的:

  // params:一个eventName的,监听器,capturePhase,优先级,将useWeakReference
someObj.addEventListener(eventName的,myFunct,假,0,真正的);
 

和使用unloadAndStop();并首先删除!

  removeChild之(fl_ProLoader_3);
fl_ProLoader_3.unloadAndStop();
fl_ProLoader_3 = NULL;
 

和跟踪装载后空它,看看有什么输出说!

Having a little trouble with an Flash for iOS application! I have a button "start" which loads an external swf. Then I have a different button, "home", which should do three things:

  1. unload the external swf
  2. stop all sounds
  3. return to frame 1

It all SEEMS to work, but then it appears that the SWF never unloads! I keep hearing it over and over again.

  //code on frame follows...mythbutt_home


 stop();

//home button

mythbutt_home.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_4);

function fl_ClickToGoToAndStopAtFrame_4(event:MouseEvent):void
{
removeChild(fl_ProLoader_3);

}
mythbutt_home.addEventListener(MouseEvent.CLICK, fl_ClickToStopAllSounds);

function fl_ClickToStopAllSounds(event:MouseEvent):void
{
SoundMixer.stopAll();
}

mythbutt_home.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_1);

function fl_ClickToGoToAndStopAtFrame_1(event:MouseEvent):void
{
gotoAndStop(1);
}


//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;
}

解决方案

First off you shouldnt be doing this over multible Frames. It would be best to use external .as files. To properly unload the swf you need to delete all refrences to the swf itself and objects in the swf. This includes EventListeners for which you should use a weak refference like this:

// params: eventName, listener, capturePhase, priority, useWeakReference
someObj.addEventListener("eventName",myFunct,false,0,true);

and use unloadAndStop(); and remove first!

removeChild(fl_ProLoader_3);
fl_ProLoader_3.unloadAndStop();
fl_ProLoader_3 = null;

And trace the loader after you null it, and see what the output says!

这篇关于动作脚本3.0的问题,我的SWF不卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆