Highlighted

Recalling the last frame of a movieclip as the current frame.

Explorer ,
Feb 05, 2019

Copy link to clipboard

Copied

Ok, I am finally moving over from AS2 to AS3 creating an escape game. As you move from frame to frame on the main timeline, I want some tweened movieclips to stay in there last position (frame) where you left them. For example, you unlock a closed door. The tween animation is the door swinging open and the last frame has a stop(); applied to it. Clicking on the open door takes you to the next frame. Going back through the door brings you back to the previous frame. I would like to show the original door movieclip tween on it's last frame - opened instead of resetting to frame 1. The only reference I have is the AS2 code.

This is placed on the first frame of the tween:

if(_root.mcName_mc_lastFrame){

      this.gotoAndStop(_root.mcName_mc_lastFrame);

}

And this is placed on the frame I want to be recalled whenever the player comes back to the room:

_root.mcName_mc_lastFrame=this._currentframe;

Can someone show me the equivalent of this code in AS3? Greatly appreciated!

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

Hi.

One approach is to create some properties on the main timeline itself so you can check the states of things when you move forth and back.

Here is a sample of how you can achieve this.

AS3 code:

[Frame 1]

import flash.events.MouseEvent;

function checkSave():void

{

    if (!this.started)

    {

        this.states =

        {

            door:

            {

                open:false

            }

        };

      

        this.started = true;

    }

  

    setDoor();

}

function setDoor():void

{

    door.addEventListener(MouseEvent.CLICK, checkDoor);

    if (this.states["door"].open)

        door.gotoAndStop(door.totalFrames);

}

function checkDoor(e:MouseEvent):void

{

    if (e.currentTarget.currentFrame == 1)

    {

        e.currentTarget.gotoAndPlay(2);

        this.states["door"].open = true;

    }      

    else if (e.currentTarget.currentFrame == e.currentTarget.totalFrames)

        gotoAndStop("darkRoom");

}

function backToStart(e:MouseEvent):void

{

    gotoAndStop("start");

}

stop();

checkSave();

[Frame 2]

backButton.addEventListener(MouseEvent.CLICK, backToStart);

FLA download:

animate_cc_as3_keep_states.zip - Google Drive

I hope this helps.

Regards,

JC

TOPICS
ActionScript

Views

130

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Recalling the last frame of a movieclip as the current frame.

Explorer ,
Feb 05, 2019

Copy link to clipboard

Copied

Ok, I am finally moving over from AS2 to AS3 creating an escape game. As you move from frame to frame on the main timeline, I want some tweened movieclips to stay in there last position (frame) where you left them. For example, you unlock a closed door. The tween animation is the door swinging open and the last frame has a stop(); applied to it. Clicking on the open door takes you to the next frame. Going back through the door brings you back to the previous frame. I would like to show the original door movieclip tween on it's last frame - opened instead of resetting to frame 1. The only reference I have is the AS2 code.

This is placed on the first frame of the tween:

if(_root.mcName_mc_lastFrame){

      this.gotoAndStop(_root.mcName_mc_lastFrame);

}

And this is placed on the frame I want to be recalled whenever the player comes back to the room:

_root.mcName_mc_lastFrame=this._currentframe;

Can someone show me the equivalent of this code in AS3? Greatly appreciated!

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

Hi.

One approach is to create some properties on the main timeline itself so you can check the states of things when you move forth and back.

Here is a sample of how you can achieve this.

AS3 code:

[Frame 1]

import flash.events.MouseEvent;

function checkSave():void

{

    if (!this.started)

    {

        this.states =

        {

            door:

            {

                open:false

            }

        };

      

        this.started = true;

    }

  

    setDoor();

}

function setDoor():void

{

    door.addEventListener(MouseEvent.CLICK, checkDoor);

    if (this.states["door"].open)

        door.gotoAndStop(door.totalFrames);

}

function checkDoor(e:MouseEvent):void

{

    if (e.currentTarget.currentFrame == 1)

    {

        e.currentTarget.gotoAndPlay(2);

        this.states["door"].open = true;

    }      

    else if (e.currentTarget.currentFrame == e.currentTarget.totalFrames)

        gotoAndStop("darkRoom");

}

function backToStart(e:MouseEvent):void

{

    gotoAndStop("start");

}

stop();

checkSave();

[Frame 2]

backButton.addEventListener(MouseEvent.CLICK, backToStart);

FLA download:

animate_cc_as3_keep_states.zip - Google Drive

I hope this helps.

Regards,

JC

TOPICS
ActionScript

Views

131

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 05, 2019 0
Adobe Community Professional ,
Feb 06, 2019

Copy link to clipboard

Copied

Hi.

One approach is to create some properties on the main timeline itself so you can check the states of things when you move forth and back.

Here is a sample of how you can achieve this.

AS3 code:

[Frame 1]

import flash.events.MouseEvent;

function checkSave():void

{

    if (!this.started)

    {

        this.states =

        {

            door:

            {

                open:false

            }

        };

      

        this.started = true;

    }

  

    setDoor();

}

function setDoor():void

{

    door.addEventListener(MouseEvent.CLICK, checkDoor);

    if (this.states["door"].open)

        door.gotoAndStop(door.totalFrames);

}

function checkDoor(e:MouseEvent):void

{

    if (e.currentTarget.currentFrame == 1)

    {

        e.currentTarget.gotoAndPlay(2);

        this.states["door"].open = true;

    }      

    else if (e.currentTarget.currentFrame == e.currentTarget.totalFrames)

        gotoAndStop("darkRoom");

}

function backToStart(e:MouseEvent):void

{

    gotoAndStop("start");

}

stop();

checkSave();

[Frame 2]

backButton.addEventListener(MouseEvent.CLICK, backToStart);

FLA download:

animate_cc_as3_keep_states.zip - Google Drive

I hope this helps.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2019 0
Explorer ,
Feb 06, 2019

Copy link to clipboard

Copied

Thank you for a quick reply! And for the .fla example. My fault, I forgot to mention I would like a separate button to open the door, like an elevator button instead of clicking on the door MC itself. Can this be integrated into your existing code?

Thank you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2019 1
Adobe Community Professional ,
Feb 06, 2019

Copy link to clipboard

Copied

Nice!

Sure. No problem.

Here is:

AS3 code:

import flash.events.MouseEvent;

function checkSave():void

{

    if (!this.started)

    {

        this.states =

        {

            door:

            {

                open:false

            }

        };

       

        this.started = true;

    }

   

    setDoor();

}

function setDoor():void

{

    door.addEventListener(MouseEvent.CLICK, checkDoor);

    if (this.states["door"].open)

        door.gotoAndStop(door.totalFrames);

    else

        button.addEventListener(MouseEvent.CLICK, callElevator);

}

function callElevator(e:MouseEvent):void

{

    if (door.currentFrame == 1)

        door.gotoAndPlay(2);

}

function checkDoor(e:MouseEvent):void

{

    if (door.currentFrame == door.totalFrames)

    {

        this.states["door"].open = true;

        gotoAndStop("darkRoom");

    }

}

function backToStart(e:MouseEvent):void

{

    gotoAndStop("start");

}

stop();

checkSave();

FLA download:

animate_cc_as3_keep_states_02.zip - Google Drive

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2019 1
Explorer ,
Feb 06, 2019

Copy link to clipboard

Copied

Hey, Thanks! It worked great. I'm going to try and apply this method to other ideas as well. I have never seen anyone go the extra mile and produce a flash file to go with it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2019 1
Adobe Community Professional ,
Feb 07, 2019

Copy link to clipboard

Copied

Excellent!

You're welcome!

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 07, 2019 0