A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Jump to Frame in the end after playing

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    3

    Jump to Frame in the end after playing

    I am a newbie on AS3 and totally lost. I dont know if this has been asked earlier but here it is.

    I have a set of links and all the links would play the same label. However, at the end (like after 100 frames) there would be another script that would make its jump to a certain frame. So if a user clicks the about link, it will play the transitional frames and jump to the about frame in the end. I can do it in AS2 but AS3 is totally new for me. Any idea?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Have the functions on the first links set a variable/property on the main timeline, and the second script refer to that variable to see where to go.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    3
    Quote Originally Posted by 5TonsOfFlax View Post
    Have the functions on the first links set a variable/property on the main timeline, and the second script refer to that variable to see where to go.

    errrmmm....how do we do that? I only know playing a certain frame like this:

    Object(root).about.addEventListener(MouseEvent.CLI CK, _click);

    function _click(event:MouseEvent):void
    {
    gotoAndPlay("go");
    }


    NOTHING MORE
    :-(

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Code:
    var dynRoot:MovieClip = MovieClip(root);
    dynRoot.about.addEventListener(MouseEvent.CLICK, _click);
    
    function _click(event:MouseEvent):void{
      dynRoot.afterGo = "about";
      gotoAndPlay("go");
    }
    Then in the frame where you want to jump at the end of the "go" section:
    Code:
    var dynRoot:MovieClip = MovieClip(root);
    gotoAndStop(dynRoot.afterGo);
    The reason we need to set a property on the root object rather than just a variable is that a variable would be local to the frame it's on and would fall out of scope after that frame was over.

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    3
    Thanks a lot. It did work for one link but then how does it work when I have like 5 more links. I mean what exactly do i cahnge to make it work for all.

    (this would be the dumbest question im assuming so sorry in advance)

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    board ate my last reply.
    Let's say you have "menu" which is just like about. Make its listener just like "about"'s, but with a different destination.
    Code:
    function _menuclick(event:MouseEvent):void{
      dynRoot.afterGo = "menu";
      gotoAndPlay("go");
    }
    On the last frame, the same code as before will run, but this time it'll jump to "menu".

    You could consolidate all these listeners to one if you add a property to your button clips and reference that.
    Code:
    about.destination = "about";
    menu.destination = "menu";
    
    about.addEventListener(MouseEvent.CLICK, _click);
    menu.addEventListener(MouseEvent.CLICK, _click);
    function _click(me:MouseEvent):void{
      dynRoot.afterGo = MovieClip(me.currentTarget).destination;
      gotoAndPlay("go");
    }
    And if your frame labels are the same as your button instance names, you can just do this instead of setting a destination property:
    Code:
    function _click(me:MouseEvent):void{
      dynRoot.afterGo = MovieClip(me.currentTarget).name;
      gotoAndPlay("go");
    }
    Last edited by 5TonsOfFlax; 05-30-2012 at 10:13 AM.

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