actionscript-3flashactionscriptframe-ratescene

Actionscript 3.0 - Changing FPS for scenes won't work


I have a scene where if you push a button, it goes to a different scene.

At the beginning code of Scene 2, I have -

stage.frameRate = 40

But, to my surprise, it stays the same FPS!

Should there be a variable for it or something?


Solution

  • Your Main Timeline being a MovieClip...

    trace(this, this is MovieClip); // [object MainTimeline] true
    

    you can use the [read-only] property currentScene of a MovieClip:

    "The current scene in which the playhead is located in the timeline of the MovieClip instance."

    ...and the [read-only] property name of a Scene:

    "The name of the scene."

    Scene 1

    function modifyFrameRate():void {
        stage.frameRate = this.currentScene.name == 'Scene 1' ? 2 : 40;
    }
    modifyFrameRate();
    

    Scene 2

    modifyFrameRate();
    

    Adobe Help to read more about Scene Class.