我正在为我的移动 Air 应用程序使用来自 Flash Cs6 的代码片段。如何正确删除侦听器?(我收到错误 1120:访问未定义的属性 ocean_slider。)使用以下代码。谢谢你的帮助。
/* Deactivate/Activate Event
Conserve CPU and battery life by suspending expensive processes, such as ENTER_FRAME and TIMER events, when the application is not in focus.
Instructions:
1. Start timers and add event listeners in "fl_Activate".
2. Stop timers and remove event listeners in "fl_Deactivate".
*/
stage.addEventListener(Event.ACTIVATE, fl_Activate);
stage.addEventListener(Event.DEACTIVATE, fl_Deactivate);
function fl_Activate(event:Event):void
{
// Start timers and add event listeners here.
naturepage.sliders.ocean_slider.addEventListener(Event.ENTER_FRAME, ocean_slider);
function ocean_slider(e:Event):void
{
ocean_transform.volume = (naturepage.sliders.ocean_slider.value/100);
ocean_channel.soundTransform = ocean_transform;
}
}
function fl_Deactivate(event:Event):void
{
// Stop timers and remove event listeners here.
naturepage.sliders.ocean_slider.removeEventListener(Event.ENTER_FRAME, ocean_slider);
}
好的。我只是将代码更改为以下,但仍然有问题。监听器肯定会被添加,因为这些函数在没有 removeEventListener 的情况下发布后在我的应用程序中工作。但是,一旦我添加了删除侦听器的代码,当我尝试发布时就会收到错误 1120。
stage.addEventListener(Event.ACTIVATE, fl_Activate);
stage.addEventListener(Event.DEACTIVATE, fl_Deactivate);
function fl_Activate(event:Event):void
{
addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event):void
{
ocean_transform.volume = (naturepage.sliders.ocean_slider.value/100);
ocean_channel.soundTransform = ocean_transform;
}
}
function fl_Deactivate(event:Event):void
{
removeEventListener(Event.ENTER_FRAME,myFunction);
}