vendredi 14 avril 2017

Actionscript 3 - Why is this variable increasing?

I am trying to create a general class to use in my flash projects : a "GameSceneSprite" which is basically a movieClip which manages the 3 phases a display object usually has : the intro, the active/interactive time, the outro. Should be very useful to make menus, for instance.

It seemed to work fine, until an unexpected problem came. Here is the part that poses a problem, it's in the outro part.

    //ACTIVATE CLICK
    //----------------------------------------
    override public function makeInteractive() {
        (this.parent as MAIN).addEventListener( MouseEvent.MOUSE_UP , clickOnParent );
    }

    //REACT TO CLICK
    //----------------------------------------
    protected function clickOnParent (e:MouseEvent) {

        //Only react to clic if interface clip wasn't the one clicked
        var commonsMenu = (parent as MAIN).getChildAt(2) as MovieClip;

        if ( !commonsMenu.contains( e.target as DisplayObject ) ) {
            stopInteractive();
        }

    }

    //STOP INTERACTIVE PHASE
    //----------------------------------------
    override protected function stopInteractive() {

        (this.parent as MAIN).removeEventListener( MouseEvent.MOUSE_UP , clickOnParent );
        startOutro( 0.01 );

    }

    //------------------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------- OUTRO ----------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------------------    

    //START L'OUTRO
    //----------------------------------------
    override public function startOutro( _duration:Number ) {

        trace ( this , " - OUTRO STARTED" );

        this.mainTimer.start();
        this.TIMECODES_mainTimer = new Array();
        this.TIMECODES_mainTimer.push( _duration*1000 );

        this.currentTimeCode = 0;

        this.currentStatus = CONFIG.CONST_FILE.GAMESCENESPRITE_CODE_OUTRO;
        this.addEventListener( Event.ENTER_FRAME , playOutro );

        //Define event timecodes
        this.TIMECODES_mainTimer.unshift( );
        //***TO DO : ADD ACTUAL INTRO WITH ACTUAL TIMECODES***

    }

    //PLAY CLIP OUTRO
    //----------------------------------------
    override protected function playOutro( e:Event ) {

        var hasReached_Timecode:Boolean = ( this.mainTimer.getElapsed() >= this.TIMECODES_mainTimer[currentTimeCode] );

        //If we reach a timecode, go to next. If it was the last timecode, end function there.
        if ( hasReached_Timecode ){

            this.currentTimeCode++;
            if ( this.currentTimeCode >= this.TIMECODES_mainTimer.length ) { outroEnds(); return; }

        }

        //TO DO : ADD TIMECODE CODE

    }

    //END OF OUTRO
    //----------------------------------------
    override public function outroEnds() {

        if ( this.currentStatus == CONFIG.CONST_FILE.GAMESCENESPRITE_CODE_OUTRO && this.hasEventListener( Event.ENTER_FRAME ) ) {

            trace ( this , " - OUTRO ENDED" );
            this.removeEventListener( Event.ENTER_FRAME , playOutro );

            removeThisAndLoadNext("MAIN_MENU_CLIP");
        }

    }

For some reason, when the outro runs, the variable "currentTimeCode" increases to 1 without the "hasReached_Timecode" boolean ever being true! Since there is nothing in TIMECODES_mainTimer[i], this leads to a comparison with undefined, and the outro just NEVER ENDS.

What could possibly cause this variable to increase?!! There is no occurrence of an increase besides the one that happens when the test is true... which it never is right now.

...I can not figure it out. Please help me!

I can provide extra code for the other parts and answers if needed. Just ask.

Aucun commentaire:

Enregistrer un commentaire