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

Back button in AS3

Explorer ,
Feb 03, 2009 Feb 03, 2009
I did a search on this and didn't find a successful answer yet. I need to have a back button in AS3 that'll remember the last frame visited from any frame in the site. There are various buttons to get to various frames, and the one back button will always be showing.

What's the script to make that happen from any frame utilizing AS3?
TOPICS
ActionScript
6.8K
Translate
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
Guest
Feb 03, 2009 Feb 03, 2009
1. label every frame that you want it to be able to go back to
e.g. page1, page2 etc

2. create a single variable to be used throughout your flash file
e.g: var backValue:String;

3. on each frame you have labeled reset the variable value to whatever the frame label is
backValue = "whatever the frame label is";

4. on your back button make it go back to the value of your variable
back.addEventListener(MouseEvent.CLICK, backFunction);
function backFunction(e:MouseEvent):void {
gotoAndStop(backValue);
}


this will only work for one page, youl have to use a array or series of variables to create a proper history
Translate
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 03, 2009 Feb 03, 2009
Thank you so much for your help. I've tried that and am getting this error:

ArgumentError: Error #2109: Frame label null not found in scene Scene 1.
at flash.display::MovieClip/gotoAndStop()
at berylstonemain2_fla::MainTimeline/backFunction()

What might I be doing wrong? The frames are labeled and the whole site is in scene1.

I'd love to make a proper history, but think this is the less ambitious and most likely to succeed solution for now.
Translate
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
Guest
Feb 03, 2009 Feb 03, 2009
are your paths correct?
as in your not telling it to look for a label called page1 on the main timeline when its actually inside a movieclip?
Translate
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 03, 2009 Feb 03, 2009
Yeah, it's a pretty simple file that I'm picking up and just editing.

So, on the first frame I have

var backValue:String;
backValue:"PageHome";


in the actionscript.

On the following frames (everything's just one main scene with frames and gotoandstops) I have, for example, the frame labeled PageAboutUs and in the actionscript window backValue:"PageAboutUs" and so on.

I'm sure there's something really basic I'm messing up here… thanks again for your help!
Translate
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
Guest
Feb 03, 2009 Feb 03, 2009
its backValue="PageAboutUs";
not
backValue:"PageAboutUs";

its always a single equals sign to assign a variable

heres a simple demo switching between 2 pages

http://www.rad-media.co.uk/example.fla
Translate
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 03, 2009 Feb 03, 2009
OK, syntax was wrong and I fixed that (I knew it had to be some silly error like that).

So now, if I go to one of the pages (frames), then go back to the home page (home frame), and click the back button it works to take you back to whatever subpage you were just on. However, it only works from the home page to go back to a subpage. You can't use the back button to go from one subpage to another you were just on, or back to the home page again. Why would that be? Is there a way to make the back button work from anywhere?

Also, it only works if I don't assign the home page a backvalue (probably why you can't go "back" to the home page). But, since it works to go back from there to any other page you were just on, I think it must be close to working across the board… just curious what the problem could be… help??
Translate
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 03, 2009 Feb 03, 2009
Would an array work to allow the back button to work throughout the site? How would I do that?
Translate
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
Guest
Feb 03, 2009 Feb 03, 2009
it sounds like it could be 1 of 2 things.

if your buttons not working at all you havent got the script with the event listener applied to the button on that frame or your variable isnt being passed through or read on the frame its stopping on.

try using trace statements to pinpoint where the problem is

trace("this bits working");
Translate
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
Guest
Feb 03, 2009 Feb 03, 2009
as for using arrays, all youd do is create an array and every time you go to a new page its adds a new element storing the frame label into the array.
when back is clicked it retrieves the previous element from the array (and deletes the top one) and goes to this page.
this way you can store as much history as yuo want aslong as you make the array long enough

have a look at this and some array tutorials and you should get an idea of what im on about
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html
Translate
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 03, 2009 Feb 03, 2009
Thank you, thank you ross_design. I think it's worth checking out arrays and looking at doing it that way. I really appreciate your time today.
Translate
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
Guest
Feb 03, 2009 Feb 03, 2009
LATEST
no probs
Translate
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