我花了很多时间试图解决这个问题。所以,基本上我有一个类(addadd(,它包含可以创建eventListener和删除eventListener的函数。我还有另外两个对象(Symbol1和Symbol2(,它们告诉函数要做什么——创建或删除。
package {
import flash.display.*;
import flash.events.Event;
import fl.motion.MotionEvent;
import flash.events.MouseEvent;
public class addadd
{
var stanishev:stanishev_line = new stanishev_line;
public function addadd()
{
// constructor code
}
public function stanishevF(par1)
{
if (par1 == "create")
{
Main.display.addChild(stanishev);
stanishev.name = "stanishev_child";
stanishev.x = -200;
stanishev.y = 500;
stanishev.gotoAndPlay("start");
stanishev.addEventListener(Event.ENTER_FRAME, frameDOstanishev);
}
else
{
trace ("asasasas");
stanishev.removeEventListener(Event.ENTER_FRAME, frameDOstanishev);
}
}
public function frameDOstanishev(e:Event)
{
trace (stanishev.currentFrame);
}
} }
package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
public class Symbol1 extends SimpleButton
{
var call_creator:addadd = new addadd;
public function Symbol1()
{
// constructor code
addEventListener(MouseEvent.MOUSE_OVER, eventResponse);
addEventListener(MouseEvent.MOUSE_DOWN, eventResponse2);
}
function eventResponse(e:MouseEvent)
{
call_creator.stanishevF("create");
}
function eventResponse2(e:MouseEvent)
{
call_creator.stanishevF("destroy");
}
} }
package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
public class Symbol2 extends SimpleButton
{
var call_creator:addadd = new addadd;
public function Symbol2()
{
// constructor code
addEventListener(MouseEvent.MOUSE_DOWN, eventResponse2);
}
function eventResponse2(e:MouseEvent)
{
call_creator.stanishevF("destroy");
}
} }
因此,我可以让addadd类创建这个eventListener,并从Symbol1中删除它,但我无法让addadd类来创建这个event侦听器,并从Symbol1发送"create"参数,然后通过发送"destroy"参数从Symbol2中删除它!!!
如何从不同的对象中创建和删除相同的eventListener?我发现这种方法会让听众更有条理,但我不确定这是否是正确的方式当我在主时间线中的帧之间移动时,侦听器出现问题(错误:1009(,所以我想在跳到另一帧之前杀死它们
感谢
您可以将public function
(比如removeListeners()
和addListeners()
(放在该类中,并从其他类调用这些函数,比如
class A ()
{
//constructor code
public function removeListeners():void
{
//remove listeners here
}
}
然后从创建了这个"A"类实例的类(例如Main.as
(中调用这个removeListeners()
public function
。