开发者

as3 conidtional statement not working

In my code here:

var manTimer:Timer = new Timer(1700,5);
manTimer.addEventListener(TimerEvent.TIMER, moveMan);
function moveMan(e:TimerEvent):void {
    var manX:Tween = new Tween(man, "x", Regular.easeIn, man.x, man.x - 100, 1.5, true);
}

function startMan(e:MouseEvent):void {
    manTimer.start();
    var manX:Tween = new Tween(man, "x", Regular.easeIn, man.x, man.x - 100, 1.5, true);
}

if(man.x > 589) {
paper.btnElScorcho.addEventListener(MouseEvent.CLICK, startMan);
paper.btnTheGoodLife.addEventListener(MouseEvent.CLICK, startMan);
}

I am trying to get it so that when btnElScorcho or btnTheGoodLife is clicked it'll move my "man" mc out onto the stage. It starts at 590px and ends at -10px. That part is working.

What is not working is my conditional statement that tells it to only move the "man" if he is at the x position of 590 or greater, because, when one of the 2 buttons is clicked again, I don't want to move him out if he is already there or if he is already moving开发者_StackOverflow中文版 out.

So for some reason, "man" will still move when the buttons are clicked a second time and oddly enough, "man" will only move twice as opposed to the normal 5 times set in the function.

Maybe I can change the if statement to check if the button has already been clicked as opposed to where "man" is?

Thanks, Wade


There's a slight misconception. addEventListener will register the handler function forever, not just for one click. What you want to do is call addEventListener at the beginning of your program once, and instead check the condition inside the handler function so that if it is false, the handler code is skipped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜