A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: _root.gotoAndPlay(varName) doesn't work

  1. #1
    Member
    Join Date
    Nov 2003
    Posts
    90

    _root.gotoAndPlay(varName) doesn't work

    Right now, I'm developing a flash game, and I have pop-up text boxes. There is a continue button on these boxes. Clicking the continue button makes the box dissapear, and on the last frame of the animation, I originally had this code -

    Code:
    _root.gotoAndStop(varNum);
    removeMovieClip(this);
    This gave me problems. varNames value was two, and when it sent me to scene two (my game is split into 3 scenes, Menu, Options, and Game) I assumed that the flash worked that way. THen I changed it.

    Code:
    _root.gotoAndStop("Game", varNum);
    removeMovieClip(this);
    However, this gave me the same problem. THen I tried...

    Code:
    tellTarget(_root) {
      gotoAndStop("Game", varNum);
    }
    removeMovieClip(this);
    and THAT wouldn't work. THen I dug down into all possible ways of doing this and tried this...

    Code:
    with(_root) {
      gotoAndStop("Game", varNum);
    }
    removeMovieClip(this);
    And, to my disbelief, it didn't work. Suggestions would be nice
    Last edited by Giblaz; 01-16-2005 at 11:08 PM.

  2. #2
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    When targeting the main timeline never target scene names or in fact frame numbers, but labeled frames instead.

    If you target a frame number, you have to understand that it's a cumulative frame number of all frames in all scenes previous to the targeted frame in the targeted scene, including the frames of a preloader if you have one...

    Thus if you were targeting frame 1 of your Game scene, and you had a 5 frames preloader scene, a 10 frames Menu scene, and a 20 frames Options scene, you actually have to target frame number -> 5+10+20+1 = 36, to actually end up on frame 36. This is more error prone, and furthermore if you ever edit your previous scenes (shorthen them for example...), you'd have to re-calculate and change all of your goto's.

    Target a labeled frame instead. Label the targeted frame in the targeted scene with an unique label such as my_target, add _root or _level0 to your path and target the labeled frame...
    code:

    on(release){
    _level0.gotoAndStop("my_target");
    }



    See my first post in this thread about targeting labeled frames and how to set them up...

    http://www.flashkit.com/board/showth...hreadid=584159 // labels

    Oh! And next time use AS & /AS tags rather than PHP ones... To hard on my old eyes!
    Last edited by oldnewbie; 01-16-2005 at 11:01 PM.

  3. #3
    Member
    Join Date
    Nov 2003
    Posts
    90
    Thanks a bunch! That's very helpful, because now I can just make the equation _root.gotoAndPlay(varName + 8) assuming 8 frames are whats ahead in my movie (which it is)

    Cheers

  4. #4
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Watch it if you ever edit those though, forget and start wondering why it ain't working anymore!

  5. #5
    Member
    Join Date
    Nov 2003
    Posts
    90
    hmm, it would probably be a good idea to make it a variable so I can change it in case I encounter that problem...

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