9 Replies Latest reply on Oct 17, 2006 5:37 PM by twistedpancreas

    play animation on main timeline from within a mc

    twistedpancreas Level 1
      this is probably the most basic question of the day, but how do you get the main timeline to play from within a mc?

      say I have a mc called jolly_mc and within it is an action on it's timeline at keyframe 10. That action needs to jump to a certain frame on the main timeline and play.

      I've tried

      _level0.gotoAndPlay(492);

      _root.gotoAndPlay(492);

      _level0.gotoAndPlay("animation");

      _root.gotoAndPlay("animation");

      and non of these work, can anyone clear the haze in my day :)

      thanks in advance.
        • 1. Re: play animation on main timeline from within a mc
          Craig Grummitt Level 3
          they all look okay...? of course jolly_mc telling the root to do something doesn't mean that jolly_mc will stop playing or whatever its doing. unless the frame on the _root no longer contains jolly_mc.

          is it definitely reaching the gotoAndPlay? have you put a trace next to it?
          • 2. Re: play animation on main timeline from within a mc
            twistedpancreas Level 1
            hmm i solved the problem but discovered a new problem.

            you see jolly_mc was on frame 491 of the main timeline, there is a button inside jolly_mc that then plays from 492 onwards on the main timeline.

            Now there is all this animation before frame 491 on the main timeline, so I decided to have frame 1 on the main timeline with the following code

            onEnterFrame = function () {
            gotoAndPlay(491)
            }

            problem is the button inside jolly_mc doesn't work when this is used

            have i stuffed up somewhere?

            thanks for you're reply so far


            • 3. Re: play animation on main timeline from within a mc
              Craig Grummitt Level 3
              why do you have your skip gotoAndPlay inside an onEnterFrame? Are you a Director programmer by chance? ;)
              onEnterFrame sets up a loop that continues at the framerate until onEnterFrame is deleted. You can move to frame 491 if you like, but the onEnterFrame event handler will keep chugging on. In your case, it goes to frame 491 perpetually...
              your code on frame 1 - just remove the onEnterFrame handler and have a solo gotoAndPlay line and you should be right.
              • 4. Re: play animation on main timeline from within a mc
                twistedpancreas Level 1
                yeah i used to use Director but that was a while ago.

                ok i've given that a go and it works, thanks
                • 5. play animation on main timeline from within a mc
                  twistedpancreas Level 1
                  actually nope it's still not working

                  i'm working on a file which has this AS in a mc (on a keyframe) that is within the mc named "bkg"

                  stop();

                  _root.mainText = "Obtain 0.2 grams of Ascorbic Acid using the Spattula.";

                  this._root.bkg.gotoAndStop(3);

                  this._level0.bkg.power.powerOne.gotoAndStop(2);

                  now for some reason the

                  this._root.bkg.gotoAndStop(3);

                  doesn't work, but the

                  this._level0.bkg.power.powerOne.gotoAndStop(2);

                  does

                  is there something blatently wrong that i've missed (ie are the full stops in the _root.mainText upsetting the code)? and how exactly do i trace these?

                  eg is it

                  trace(this._root.bkg)

                  ?
                  • 6. play animation on main timeline from within a mc
                    Craig Grummitt Level 3
                    _root.mainText = "Obtain 0.2 grams of Ascorbic Acid using the Spattula.";
                    This line is fine. It's fine to have full-stops inside a string. It doesn't effect the code.

                    this._root.bkg.gotoAndStop(3);
                    Your pathing is a little strange in this line. As you can't go any further up the hierarchical tree than _root, if you're referencing objects via the root, it should be the first object in the target. So if you want to refer to your target using an absolute reference(ie by using root) then your line should read:
                    _root.bkg.gotoAndStop(3);
                    alternatively, since your AS is in a movieclip inside bkg, you can refer to your target using a relative reference like so:
                    this._parent.gotoAndStop(3);

                    this._level0.bkg.power.powerOne.gotoAndStop(2);
                    similar story here. _level0 is the highest up you can go, so putting this before it is a little strange. Fixing this using absolute referencing:
                    _level0.bkg.power.powerOne.gotoAndStop(2);
                    or:
                    _root.bkg.power.powerOne.gotoAndStop(2);
                    or relative referencing(assuming the movieclip where the AS is is not power):
                    this._parent.power.powerOne.gotoAndStop(2);
                    if it is power then you could have simply written:
                    powerOne.gotoAndStop(2);

                    yes, the syntax you suggested for trace is correct.

                    but anyway, i don't think that any of this advice is helping you with your problem. sorry i can't see the solution with the information you've provided. maybe upload?

                    how'd you go with sourcing a flash book?
                    • 7. Re: play animation on main timeline from within a mc
                      twistedpancreas Level 1
                      ok thanks for the crash course on referencing between mc's Craig. I've got myself "Actionscript for Flash 8" but haven't gotton up to the chapter on scope yet (damn work gets in the way :D )

                      so here's my file (you're meant to drag the weighingBoat onto the balance, then click the tare button which makes the digits go to 0. Then the code should enable the spattula to be moved, but it never reaches that).

                      http://home.exetel.com.au/twistedpancreas/images/chemistry.fla

                      you'll see if you go into the balance machine mc (called "balance" inside the mc called "bkg") on it's last keyframe it has the mentioned code

                      ie :

                      _level0.bkg.gotoAndStop(3);

                      isnt working, but the following is:

                      trace(_level0.bkg)

                      _level0.bkg.power.powerOne.gotoAndStop(2);

                      and i'm stumped :(

                      what am i doing wrong?
                      • 8. Re: play animation on main timeline from within a mc
                        Craig Grummitt Level 3
                        we're going in circles a bit here twistedpancreas! the problem is on the very first frame of your file:
                        onEnterFrame = function () {
                        bkg.gotoAndStop(2)
                        }
                        this handler perpetually sends bkg to frame 2. so it doesn't matter if you try to send bkg to frame 3 somewhere else, this onEnterFrame will immediately send it back to frame 2.
                        • 9. Re: play animation on main timeline from within a mc
                          twistedpancreas Level 1
                          man i give you permission to slap me silly!!!

                          sorry that fla is only a part of a bigger fla and i totally missed that!

                          so i apologise big-time!

                          thanks for all you're help and patience once again