as3声明一个eventListener - 变量范围

时间:2013-05-16 23:18:35

标签: actionscript-3 scope addeventlistener

如何宣布事件监听器是公开的,以便所有功能都可以使用?

// Coded needed below to declare Event

function addEventL()
   {
   /// Declares it in a function
   myMovie.addEventListener(MouseEvent.CLICK, menuIn);
   }

function removeEventL()
   {
   /// This does not work because it was first called in a function.
   /// So it can not find the event Listener to remove.  
   myMovie.removeEventListener(MouseEvent.CLICK, menuIn);
   }

1 个答案:

答案 0 :(得分:0)

将嵌套事件监听器的函数转换为公共函数:

package example
{ 
 public function addEventL()
 {
 /// Declares it in a function
 myMovie.addEventListener(MouseEvent.CLICK, menuIn);
 }
}