PDA

View Full Version : [AS3] whenever I return to frame 1, all of the things that have happened are reset


Fear_Plot
09-22-2009, 12:29 AM
I'm in the middle of an Escape the Room game (it's my first one). Everything was going fine until I realized that whenever I return to frame 1, all of the things that have happened are reset.

Ex: I pick up an item. I can go to any frame, but if I go to frame 1 the item reappears in its original frame and is no longer in my inventory.

Can anyone offer any help?

RogerClark
09-22-2009, 01:10 AM
This may seem like a stupid question, but why are you going back to frame 1?

With frames based programming, Frame is often the initialisation code where everthing is reset.

So if you move the play head back to Frame 1 everything is likely to be reset.

don't use gotoAndStop(1) or gotoAndPlay(1) unless you want to reset.

If you code is looping back to Frame 1 for some reason, make sure that each of your key frames in which you have code has the stop(); instuction in it, as this will prevent the play head from moving.
NB. You may have some frames were you want animation, so don't put stop(); on those frames.
But its fairly normal for any frame with Actionscript in it to have stop(); as the first line of code

Fear_Plot
09-24-2009, 10:58 PM
So, based on what you've said I'm going to assume that most if not all games use frame 1 as the "Play Button" or "Menu."

If this is true, I assume that resetting does not matter because there is no way to return to the Menu Screen (unless there is a "return to Menu" option in-game).

So, I should be fine if I include a play button as frame 1, because in that case my game-play frames will be from frame 2 and on, meaning that they will never reset mid-play (because only frame 1 will reset).

Is that right?

RogerClark
09-24-2009, 11:47 PM
There are many ways to do this.

But in your case if you want a menu on at the start of your game, you may as well put it on Frame 1.

Also put all of your initialisation on frame one

e.g.
var score:Number = 0

Then as long as you don't go back to frame 1 you won't reset that sort of stuff.

Of course if someone presses the Refresh button in the browser everything will be reset as the whole flash movie will be reloaded and will start executing at frame 1 again.


You may want to take a look at how other people have done similar things, and a good site to download complete source FLA's is www.flashkit.com

Actually if you download a few FLAs that have menu's you'll see that people do it in a number of different ways, but it may give you some ideas.


Personally I don't use the timeline very often.
I use single frame movies, and use Actionscript to call up the various screens, which are normally library symbols or external SWF files.
But if you're not used to this way of doing things or have just started with Flash, you may find it easier to do things on the timeline