如何在as3中多次使用stage事件

时间:2013-12-01 20:34:42

标签: actionscript-3

这是我的代码:

stop();
import gs.*; 
import gs.easing.*;
import gs.TweenMax;


stage.addEventListener(MouseEvent.CLICK, rijden); // Add the button click

function rijden(e:MouseEvent):void {
TweenLite.to(auto, 4, {x:666.15, y:375.6});

}

var grav:Number = 7.5;
var jumping:Boolean = false;
var jumpPow:Number = 0;

stage.addEventListener(MouseEvent.CLICK, spring); // Add the button click

stage.addEventListener(Event.ENTER_FRAME, update);

function spring(e:MouseEvent):void {

        if(jumping != true)
        {   
            TweenLite.to(man, 0.5, {rotation:360});
            jumpPow = -50;
            jumping = true;
        }
    }   



function update(evt:Event):void
{
    if(jumping)
    {
        man.y += jumpPow;
        jumpPow += grav;

        if(man.y >= 375)
        {
            jumping = false;
            man.y = 375;
                    }
    }
}

但现在如果我点击舞台,两个对象都会开始补间或其他东西。但它必须是这样的:如果我点击舞台:第一个功能rijden需要激活,在第二个点击舞台功能弹簧需要激活。 有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

重新格式化您的代码:

//...

stage.addEventListener(MouseEvent.CLICK, rijden); // Add the button click

function rijden(e:MouseEvent):void {

     stage.removeEventListener(MouseEvent.CLICK, rijden); // unplug "rijden" handler
     stage.addEventListener(MouseEvent.CLICK, spring); // Add the button click

     TweenLite.to(auto, 4, {x:666.15, y:375.6});

}

var grav:Number = 7.5;
var jumping:Boolean = false;
var jumpPow:Number = 0;

stage.addEventListener(Event.ENTER_FRAME, update);

function spring(e:MouseEvent):void {

    stage.removeEventListener(MouseEvent.CLICK, spring); // unplug "spring" handler

    if(jumping != true)
        {   
            TweenLite.to(man, 0.5, {rotation:360});
            jumpPow = -50;
            jumping = true;
        }  

}  

//...