A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Back button (link)

  1. #1
    Member
    Join Date
    Jul 2003
    Location
    UK
    Posts
    43

    Back button (link)

    Hi all

    I did try and do a search for this topic but the search never seems to work for me here, keep getting ‘cannot find server’ so I gave up and posted this.

    I’m trying to create a back button in my movie. I don’t want to use the browsers back button just a back feature within the movie file.

    My idea is for my visitors to click a back link which will take them back to the previous page in my movie (on a time line).

    I have a movie called ‘pages’ where I have placed my separate pages of interest on the timeline.

    i.e.

    frame1 = about us (stop)
    frame2 =contact (stop),
    and so forth up to frame 9

    Say a visitor clicks on ‘contact’ and then clicks on ‘about us’, then presses the back link, it will take them to ‘contact’

    I’m not sure how this would work and if possible at all. Any help would be grateful.

    Thanks
    Sims

  2. #2
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    store the previous page number into a variable and then when you press the back button, goto that frame. So when you have a button to change pages, use code like this:
    Code:
    on(release){
      prevPage = _currentframe;
      gotoAndStop(...
    }
    Then, for your back button:
    Code:
    on(release){
    gotoAndStop(prevPage);
    }
    If you want to be able to hit back multiple times, youll have to store them in an array or stack.

  3. #3
    Member
    Join Date
    Jul 2003
    Location
    UK
    Posts
    43
    Sorry I'm a bit thick here, I'm still learning flash and not used to all the rules yet.

    This is what I did. On my frames I added an Action like so to all:

    frame = "1";
    frame = "2"; and so forth up to frame 9,

    Then on my button I added this to the action:

    on(release){
    gotoAndStop(prevPage);
    }

    So I'm not sure where I place this code:

    on(release){
    prevPage = _currentframe;
    gotoAndStop(...
    }

    Really sorry to be thick but I just don't understand. I didn't create the site only trying to help update a template a friend purchased.

    I have found this in a link!!

    on (rollOver) {
    gotoAndPlay(2);
    }
    on (rollOut) {
    gotoAndPlay(7);
    }
    on (release) {
    _root.link = 8;
    _root.gates.gotoAndPlay("s1");
    }

    Not sure if thats any help.
    Last edited by Simsyuk; 05-17-2005 at 07:01 PM.

  4. #4
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    You dont need that first part. Heres how you would have it set up:
    For the back button always use this code:
    Frame 1: prevPage = 1;
    Back Buttons:
    Code:
    on(release){
    gotoAndStop(prevPage);
    }
    All Buttons that change to other pages:
    Code:
    on(release){
    prevPage = _currentframe;
    gotoAndStop(... //where this is whatever the code you already have
    }
    This will only go back once though. Then, if you hit the back button again it will just stay on that current page. Tell me if you want to implement multiple go backs.

  5. #5
    Member
    Join Date
    Jul 2003
    Location
    UK
    Posts
    43
    Thank you for that, and yes please do explain how I can do multiple go backs.

    Thanks for your help.

  6. #6
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    Ok. well if you understand the previous part than this should be simple. Rather than using a single variable to store the previous page number, we want to use an array so that we can store multiple numbers. In frame one we need the following:
    Code:
    prevPage = new Array();
    prevPage will be an array consisting of the previous page numbers. Now, each time we visit a new page we want to store the previous page into this array. So on each button that changes pages (besides back buttons) use this:
    Code:
    prevPage.push(_currentframe);
    gotoAndPlay(... //whatever you had before
    Finally, whenever we use the back button, we need to take the most recent(last) value from the prevPage array and go to that page, and then delete that value from the array. This code goes in you back button:
    Code:
    on(release){
    pageGoto=prevPage.pop();
    if(pageGoto){ //check to see make sure array wasnt empty
      gotoAndPlay(pageGoto)
    }
    }
    You can look up what the push and pop functions do. Here a link for that.

    Thats it! Tell me how it works for you.

    ** I didnt test this code. I am pretty sure it will work but you might have some trouble with the "if(pageGoto)" line. I forget if it returns false or -1 if it cant pop anything off. Just use trace() to figure it out

  7. #7
    Member
    Join Date
    Jul 2003
    Location
    UK
    Posts
    43
    Thanks Dricciotti

    I waited for the new multiple codes before I used them.

    This is what I did. On each frame of the movie I placed this code (9 frames):
    PHP Code:
    prevPage = new Array(); 
    This is the code I used in my buttons to link to each page (9 pages placed on one movie timeframe), each page has it's own frame:

    PHP Code:
    prevPage.push(_currentframe);
    gotoAndPlay(
    on (rollOver) {
        
    gotoAndPlay(2);
    }
    on (rollOut) {
        
    gotoAndPlay(7);
    }
    on (release) {
        
    _root.link 9;
        
    _root.gates.gotoAndPlay("s1");

    And for my back button (I placed the same back button for each frame):
    PHP Code:
    on(release){
    pageGoto=prevPage.pop();
    if(
    pageGoto){ 
      
    gotoAndPlay(pageGoto)
    }

    Now I know what you're thinking, what a nutter he didn't understand a thing

    What have I done wrong? Plz and thanks you

  8. #8
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    prevPage = new Array(); only goes in the first frame. This declares a new array so you only want to do that one time, so put it in your preloader or somewhere and only put it once.

    Next, I dont know why your doing this, but heres how it would work:
    Code:
    on (rollOver) {
        gotoAndPlay(2);
    }
    on (rollOut) {
        gotoAndPlay(7);
    }
    on (release) {
        prevPage.push(_root.gates._currentframe);
        _root.link = 9;
        _root.gates.gotoAndPlay("s1");
    }
    You only want to record (push) the current frame when you are switching pages. Right? So, but that code in the release statement right before you switch pages.

    Go over this code and really understand what it does, dont just copy and paste. Make sure you know what gotoAndPlay(), on(release), on(rollOut),push(),pop(), and new Array() do; you can look up functions online or search the forums here. Also, make sure you know how to talk to movie clips within movie clips (like when you use _root.gates.gotoAndPlay() vs. just gotoAndPlay()). Then, make sure you get the concept down of what we are trying to do.
    Last edited by Dricciotti; 05-18-2005 at 04:10 PM.

  9. #9
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    To clarify, make sure you know what an array is too and how push() and pop() are used with arrays to store values in and take them back out in the order they were put it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center