A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [F8] Redirection in timeline.

  1. #1
    nefarious2all
    Guest

    [F8] Redirection in timeline.

    I tried finding an answer to this problem a couple months ago and I got an answer, just not an answer that worked for my specific problem. Perhaps because I didn't explain my question well enough ... so I'm trying again.

    I have three menu items (buttons A, B, C), each one showing you something different on the stage when clicked. It's the transition from menu item to menu item that I need help with.

    You're viewing the contents of button A, you then click on button B and a segment of the timeline plays out (segment 1). At the end of segment 1 you are directed to the segment in the timeline that shows you the contents of button B.
    Now, if you're back viewing the contents of button A and you decide to click button C, segment 1 will play out and at the end of segment 1 you are directed to the segment in the timeline that shows you the contents of button C.


    It's that segment 1 in the timeline that I want to reuse but at the end of segment 1 you are directed to a different part in the timeline depending on which button you initially clicked. I kinda see a "if button B was clicked, go here", "if button C was clicked, go there" at the end of the segment in the timeline I want to reuse. I just don't know what the scripting for something like that is. I'm quite new with ActionScript.

    Thank you in advance for any help!

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    so you just need one variable that will hold the destination (the label where you want the timeline to go at the end of each segment.

    example of script on buttons:

    buttonB.onPress = function() {
    myDestination = "segmentB";
    };

    buttonA.onPress = function() {
    myDestination = "segmentA";
    };

    And on a frame at the end of each sections:

    gotoAndPlay(myDestination);//no quotes, it's an expression

    gparis

  3. #3
    nefarious2all
    Guest
    Thank you very much for your help, but sadly my lack of knowledge with actionscript has stopped me yet again.

    Using the scripting example you've given, when I test the movie I get this error, "Statement must appear within on handler". And of course I couldn't fix it.

    Now, when I was attempting to solve this little error myself a thought occured to me. The script you've given is for when the movie reaches the end of segment 1. It redirects the play to the desired segment (segmentB, segmentA). What in this script directs the play to the beginning of segment 1?

    You click on button B, it goes to the beginning of segment 1, plays, then at the end of segment 1 the play is directed to segmentB. If I had 5 buttons and you clicked on any one of them I want them to be directed to the beginning of segment 1 then at the end of segment 1, directed to segmentC or D or E.

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    you mean you ALWAYS want segment 1 to play before B, C or D?
    If so:
    Code:
    buttonB.onPress = function() {
    myDestination = "segmentB";
    };
    buttonB.onRelease = function() {
    gotoAndPlay("segment1");
    };
    seems logical enough.

    *note: that script is supposed to be on a frame. Replace the buttons instance names with your own.

    gparis

  5. #5
    nefarious2all
    Guest
    I really appreciate all your help!! But I've run into a couple of snags.

    The first snag is, when I press buttonB it goes to the beginning of segment1 nicely enough. But when I press buttonC it doesn't go anywhere, it doesn't do anything.
    The second snag is, when I press buttonB, it plays segment1 but at the end of segment1 it jumps to the very beginning of the movie, not to segmentB.
    I've checked the spelling of all my labels and there's no mistakes there. And for the first snag I checked everything for buttonB and made sure things were identical (except for labes and such) to buttonC. Below is what I've got on the frame, pretty much what you showed me ... though for my actual movie I do change the names accordingly ...

    Code:
    buttonB.onRelease = function() {
    	gotoAndPlay("segment1");
    };
    buttonB.onPress = function() {
    	theDestination = "segmentB";
    };
    buttonC.onRelease = function() {
    	gotoAndPlay("segment1");
    };
    buttonC.onPress = function() {
    	theDestination = "segmentC";
    };
    And I have this on the last frame of segment1
    Code:
    gotoAndPlay(theDestination);

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Here's a .fla with your code.
    This one works. Maybe you'll see where yours doesn't.

    gparis
    Attached Files Attached Files

  7. #7
    nefarious2all
    Guest
    It took me about 20 to 30 times looking over your example and compairing it to my work, I retyped my script, I renamed labels, I cried .... but I got it!

    It wasn't the scripting (or labeling) at all, I had copied that right. What it was, was that I had my buttons (A, B, C ...) each on their own layer! That's what was screwing everything up. All those buttons have to be on one layer for it to work ... and it does work lovely!

    Thank you very, very much for your help!

  8. #8
    Member
    Join Date
    Oct 2000
    Posts
    93
    They dont have to be on the same layer, but they do have to already be instantiated on the timeline before you can assign any .onRelease (etc) methods to them. Having them on separate layers should not effect the functionality unless your code is being called to early based.

  9. #9
    nefarious2all
    Guest
    Really? Because when each button was on their own layer I did have them instantiated and it didn't work. Though I'm not too sure what you mean by "being called to early based".

    And I think I may have spoken too soon with my previous post ... in a way.
    When I got the script to work with my file it was after I deleted the other sceens in the movie. When I tried to get the script to work with all the sceens that's when it would jump to the very beginning of the movie after playing segment1. So, with my file that only had the one sceen (with the script working) I added a sceen in front of it and it went screwy again, the theDestination = "segmentB"; didn't work, play went to the beginning of the first sceen.

  10. #10
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Change this frame action:
    gotoAndPlay(theDestination);

    for:
    this.gotoAndPlay(theDestination);

    See attached version with scenes.

    gparis
    Attached Files Attached Files

  11. #11
    nefarious2all
    Guest
    Alright! I think this is it! I added a bit more stuff to my movie to make sure it worked perfectly this time .... and it did! Wow, I can't thank you enough gparis!

    Though I do have one tenny tinny question, and i don't know if it will be easy to explain or not. If it's complicated then don't bother.
    Why does the addition of this. to gotoAndPlay(theDestination); make it work?

    Again, thank you sooooo much! Your an

  12. #12
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    my guess is 'this' (or any timeline names like _level1.gotoAndPlay(x) etc..) is best practice for a reason. No path before the action makes the current timeline default, but it takes flash an extra step which made that single frame action not respond in time. That's only my guess.

    gp

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