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() のコードはトレースを使用して実行されますが、それでもムービーは 2 番目と 3 番目のフレームを表示していません。

ありがとう、オマー

4

1 に答える 1