1

我有以下代码在循环中运行电影并允许使用按钮在帧之间移动:

stage.displayState="fullScreen";
//stage.scaleMode = StageScaleMode.NO_SCALE;



trace("THIS IS ROOT");

var myTimer:Timer = new Timer(10000); // 10 second
myTimer.addEventListener(TimerEvent.TIMER, runFrames);
myTimer.start();

function runFrames(event:TimerEvent):void {
    var myTotNum = MainMovie.totalFrames;
    var q = MainMovie.currentFrame;

    trace("q , " + q + " total " + myTotNum);

    if (q < myTotNum) {
        trace("in frame "+q);
        while (MainMovie.numChildren > 0) {
            MainMovie.removeChildAt(0);
            trace("removed child _1. remaining count= "+MainMovie.numChildren);
        }
        MainMovie.nextFrame();
        LoadInData();       
    }
    if (q == myTotNum) {
        while (MainMovie.numChildren > 0) {
            MainMovie.removeChildAt(0);
            trace("removed child. myTotNum, remaining count= "+MainMovie.numChildren);
        }
        MainMovie.gotoAndStop(1);
    }
}// if (q < myTotNum)


// TEMP Element
function setup() {
    stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
}
setup();
function KeyPressed(evt:KeyboardEvent):void {
    switch (evt.keyCode) {
        case Keyboard.UP :
            MainMovie.prevFrame();
            resetMyTimer();
            break;
        case Keyboard.DOWN :
            MainMovie.nextFrame();
            resetMyTimer();
            break;
        case Keyboard.LEFT :
            MainMovie.prevFrame();
            resetMyTimer();
            break;
        case Keyboard.RIGHT :
            MainMovie.nextFrame();
            resetMyTimer();
            break;
    }
}

//button next
this.navBtnNext.addEventListener(MouseEvent.CLICK,navBtnNextCLICK);

function navBtnNextCLICK(e:MouseEvent):void {
    resetMyTimer();
    MainMovie.nextFrame();
}
//button previous
this.navBtnPrev.addEventListener(MouseEvent.CLICK,navBtnPrevCLICK);

function navBtnPrevCLICK(e:MouseEvent):void {
    resetMyTimer();
    MainMovie.prevFrame();
}

function resetMyTimer() {
    myTimer.reset();
    myTimer.start();
}


//----------------------------------------------- vars
    //----- generalImages
    var MainImage_01:MovieClip = new img01(); //hotDog
    var MainImage_02:MovieClip = new img02(); //pepsi 2fer
    var MainImage_04:MovieClip = new img04(); //gatorade 2 fer


    MainImage_01.x = MainImage_01.y = 0;


    var MainBg:MovieClip = new allBg_01();
    var SecondBg:MovieClip = new allBg_02();
    MainBg.x = MainBg.y = SecondBg.x = SecondBg.y = 0;

        //-----prices
        var MainPrice_01:MovieClip = new price_01();
        MainPrice_01.x = MainPrice_01.y = 0;

        var SecondPrice_01:MovieClip = new price_01_02();
        SecondPrice_01.x = SecondPrice_01.y = 0;

        var ThirdPrice_01:MovieClip = new price_01_03();
        ThirdPrice_01.x = ThirdPrice_01.y = 0;

        //-----orderConfirmation
        var OrderItem_01:MovieClip = new orderItem10();
        OrderItem_01.x = OrderItem_01.y = 0;

//----------------------------------------------- EventListener

addEventListener(Event.ENTER_FRAME, LoadData);


//----------------------------------------------- Load here - all Items
function LoadData(event:Event):void {
    LoadInData();
}//function LoadData


function LoadInData():void{
    var M = MainMovie.currentFrame;
    trace("M , " + M );

    while (MainMovie.bg.numChildren > 0) {
            MainMovie.bg.removeChildAt(0);
            this.MainMovie.imageControl.removeChildAt(0);
            this.MainMovie.priceControlA.removeChildAt(0);
            //this.MainMovie.textControl.textControlTXT.text = "PRINT IT NOW 1";
            this.MainMovie.MyOrder.itemControl.removeChildAt(0);
            trace("MainMovie.bg.numChildren, remaining count= "+MainMovie.numChildren);
        }

    if (M == 1) {
        trace("in frame "+M);
        this.MainMovie.bg.addChild(MainBg);
        this.MainMovie.imageControl.addChild(MainImage_01);
        this.MainMovie.priceControlA.addChild(MainPrice_01);
        this.MainMovie.textControl.textControlTXT.text = "PRINT IT NOW 1";
        this.MainMovie.MyOrder.itemControl.addChild(OrderItem_01);
        this.MainMovie.MyOrder.MyTotal.text = "$31";
    }//if (M == 1)



    if (M == 2) {
        trace("in frame "+M);
        this.MainMovie.bg.addChild(MainBg);
        this.MainMovie.imageControl.addChild(MainImage_02);
        this.MainMovie.priceControlA.addChild(MainPrice_01);
        this.MainMovie.textControl.textControlTXT.text = "PRINT IT NOW 2";
        this.MainMovie.MyOrder.itemControl.addChild(OrderItem_01);
        this.MainMovie.MyOrder.MyTotal.text = "$32";
    }//if (M == 2)


    if (M == 3) {
        trace("in frame "+M);
        this.MainMovie.bg.addChild(MainBg);
        this.MainMovie.imageControl.addChild(MainImage_04);
        this.MainMovie.priceControlA.addChild(MainPrice_01);
        this.MainMovie.textControl.textControlTXT.text = "PRINT IT NOW 3";
        this.MainMovie.MyOrder.itemControl.addChild(OrderItem_01);
        this.MainMovie.MyOrder.MyTotal.text = "$33";
    }//if (M == 3)


    else {

    }//else
}

出于某种原因,当我使用按钮直接更改帧(调用 LoadData())时,电影帧更改正常,但是当从 runFrames 的计时器调用相同的代码时,我得到的只是黑屏,我看到LoadInData() 中的代码是使用跟踪执行的,但电影仍然没有显示第二帧和第三帧。

谢谢, 奥马尔

4

1 回答 1

1

在您的runFrames函数中删除while loops,那些正在删除框架上的所有内容。

于 2013-10-21T17:01:42.813 回答