• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
Feb 05, 2019 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!

TOPICS
ActionScript

Views

289

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
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 06, 2019 Feb 06, 2019

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.addEventListe

...

Votes

Translate

Translate
Community Expert ,
Feb 06, 2019 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

Votes

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
community guidelines
Explorer ,
Feb 06, 2019 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.

Votes

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
community guidelines
Community Expert ,
Feb 06, 2019 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

Votes

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
community guidelines
Explorer ,
Feb 06, 2019 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.

Votes

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
community guidelines
Community Expert ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

LATEST

Excellent!

You're welcome!

Votes

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
community guidelines