Actionscript 3 如何在as3中撤消一帧中的所有代码

Actionscript 3 如何在as3中撤消一帧中的所有代码,actionscript-3,Actionscript 3,如何撤消或禁用前一帧中使用的代码? 我一直在处理事件。输入_FRAME我知道我可以使用stage.removeEventListener来撤销代码,但是我的代码有点太难了,而且我不是一个优秀的程序员,所以可能有一个简单的代码可以禁用前一帧中的所有代码,这可能吗? 这是我的代码: stop(); import com.greensock.*; import com.greensock.easing.*; import com.greensock.TweenMax; import com.gree

如何撤消或禁用前一帧中使用的代码? 我一直在处理
事件。输入_FRAME
我知道我可以使用
stage.removeEventListener
来撤销代码,但是我的代码有点太难了,而且我不是一个优秀的程序员,所以可能有一个简单的代码可以禁用前一帧中的所有代码,这可能吗? 这是我的代码:

stop();
import com.greensock.*; 
import com.greensock.easing.*;
import com.greensock.TweenMax;
import com.greensock.TweenLite;
import flash.events.Event;

var myTween:TweenLite;
stage.addEventListener(MouseEvent.CLICK, rijden); // Add the button click

function rijden(e:MouseEvent):void {
    trace('start car timer');
    stage.removeEventListener(MouseEvent.CLICK, rijden); // unplug "rijden" handler
    stage.addEventListener(MouseEvent.CLICK, spring); // Add the button click
    var randNum:Number;

    randNum = Math.round(Math.random() * 5 + 2000);
    trace(randNum);
    var timer:Timer = new Timer(randNum);
    timer.addEventListener(TimerEvent.TIMER, randGen);

    function randGen(e:TimerEvent):void {
        var timerObj:Timer = e.target as Timer;
        randNum = Math.round(Math.random() * 5 + 2000);
        myTween = TweenLite.to(auto, 4, {x:666.15, y:375.6});
        timerObj.delay = randNum;
        trace('shootCar');
        timer.stop();
    }
    timer.start();
}

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

stage.addEventListener(Event.ENTER_FRAME, update);

function spring(e:MouseEvent):void {
    trace('spring');
    stage.removeEventListener(MouseEvent.CLICK, spring); // unplug "spring" handler
    stage.addEventListener(MouseEvent.CLICK, rijden);
    if(jumping != true){   
        TweenLite.to(man, 0.5, {rotation:360});
        jumpPow = -50;
        jumping = true;
    }  
}  

function update(evt:Event):void{
    if(jumping){
        removeEventListener(Event.ENTER_FRAME, update);
        man.y += jumpPow;
        jumpPow += grav;
        if(man.y >= 375){
            jumping = false;
            man.y = 375;
        }
    }
}


var autoWasHitByMan=false;
var manWasHitByEind=false;
var autoWasHitByStopauto=false;


addEventListener(Event.ENTER_FRAME, hit);
function hit(e:Event){
    if(auto.hitTestObject(man) && !autoWasHitByMan){
        trace("auto hits man");
        autoWasHitByMan=true;
        TweenLite.to(man, 4, {x:539.95, y:145, rotation:360});
this.setChildIndex(level, this.numChildren - 1);
        TweenMax.to(level, 1, {scaleX:1, scaleY:3, ease:Elastic.easeOut});
        this.setChildIndex(facebook, this.numChildren - 1);
var timer:Timer = new Timer(2000, 1); // delay = time between ticks in milliseconds
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer.start();

function onTimerComplete(e:TimerEvent):void
{
    // remove listener
    timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
removeEventListener(Event.ENTER_FRAME, hit);
    var myTween4:TweenMax = new TweenMax(level, 1, {scaleX:0, scaleY:0, ease:Linear.easeOut});// advance playhead to frame 2
    gotoAndStop(2);



facebook.addEventListener(MouseEvent.CLICK, shareClickHandler);

function shareClickHandler(evt:MouseEvent):void
{
    var varsShare:URLVariables = new URLVariables();
    varsShare.u = 'https://play.google.com/store/apps/details?id=com.ea.games.nfs13_row';
    varsShare.t = 'Try to beat me if you can';

    var urlFacebookShare:URLRequest = new URLRequest('http://www.facebook.com/sharer.php');
    urlFacebookShare.data = varsShare;
    urlFacebookShare.method = URLRequestMethod.GET;

    navigateToURL(urlFacebookShare, '');
}

    removeEventListener(Event.ENTER_FRAME, shareClickHandler);

}
        }


    if(man.hitTestObject(eind) && !manWasHitByEind){
        trace("man hits eind");
        manWasHitByEind=true;
        man.x = 241.3;
        man.y = 375;
    }
    if(auto.hitTestObject(stopauto) && !autoWasHitByStopauto){
        trace("auto hits stopauto");
        autoWasHitByStopauto=true;
        myTween.kill();    
        auto.x = 241;
        auto.y = 375;
    }
    if(auto.hitTestObject(nextlevel) && autoWasHitByMan==false && lives > 1 ){
        trace("boeoboeobo")
        stage.removeEventListener(MouseEvent.CLICK, spring);
        stage.removeEventListener(MouseEvent.CLICK, rijden);
        stage.removeEventListener(Event.ENTER_FRAME, update);
        stage.removeEventListener(Event.ENTER_FRAME, hit);
    "this is the plce where the hit event has to be stoped I think because I get an error in the next level."
        gotoAndPlay(1, "Scène 2")
        }
}

我建议你做这件事吗?不创建类,不要在框架内编程以避免禁用代码。

不,没有简单的方法。您必须禁用哪些代码?此处有几个选项,但请在某些代码中编辑您不希望在下一帧中运行的代码。您不希望运行哪些代码?所有这些?正在删除当前不工作的侦听器,而您正在执行
stage.removeEventListener(Event.ENTER_FRAME,点击)@p1on如果TypeError:error#1009:无法访问null对象引用的属性或方法,我会收到此错误。at::MainTimeline/hit2()[::frame4:78]类型错误:错误#1009:无法访问空对象引用的属性或方法。at::main timeline/hit()[…main timeline::frame1:78]所以它指的是两个命中事件,所以我认为这两个事件或至少其中一个必须移除所以
man
display对象为空?我将您的代码复制到时间线中,并且在
hit()
man.x
中的第78行正在更改。这意味着您至少需要在尝试更改x值之前对其进行评估。这是
if(man&&man.hasOwnProperty(“x”)
switch(currentLabel)
{
    case frameLabelName:
        //your code here
    break;
    case frameLabelName2:
        //another code here
    break;
}