25 Replies Latest reply on May 24, 2006 12:51 PM by respondplease

    Rediculously dumb Actionscript question

    guttyguppygmail Level 1
      If I have a movieclip that tweens on the timeline, with a stop action on frame 1, and I put that movie clip on the root timeline, what actionscript should I write on the root timeline to tell the movieclip to play? I run into this roadblock almost every time I use flash, and forget how I solved it months later when a new project comes up. Thanks for any advice.
        • 1. Re: Rediculously dumb Actionscript question
          blemmo Level 1
          You really forget that? wow... and I thought that I had a bad memory...
          So, some reminders:
          myMC.play();
          myMC.nextFrame();
          myMC.gotoAndPlay(2);
          myMC.gotoAndPlay(myMC._currentframe+1);

          Also remember pressing the F1 key from time to time

          cheers,
          blemmo
          • 2. Re: Rediculously dumb Actionscript question
            Level 7
            guttyguppygmail,

            > If I have a movieclip that tweens on the timeline, with a
            > stop action on frame 1, and I put that movie clip on the
            > root timeline, what actionscript should I write on the root
            > timeline to tell the movieclip to play?

            When you're dealing with objects, it's a lot like dealing with people:
            just call your object by name and tell it what to do. In your case, you're
            dealing with a movie clip, so your movie clip will have to have an instance
            name (select the clip and look at the Property inspector). Once it has an
            instance name, you can "call it by name" from the main timeline (or any
            other) and tell it to do whatever movie clips can do.

            And what can movie clips do? That's all spelled out in the MovieClip
            class entry of the ActionScript 2.0 Language Reference. Classes define
            objects. Characteristics the object has are called properties; things the
            object can do are called methods; things the object can react to are called
            events.

            See this article for details.

            http://www.quip.net/blog/2006/flash/actionscript-20/ojects-building-blocks

            // in a frame of the main timeline
            mcInstanceName.play();


            David
            stiller (at) quip (dot) net
            Dev essays: http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. Re: Rediculously dumb Actionscript question
              Level 7
              Also, don't forget to give your clip an instance name in the properties
              panel after you drag it on stage. You'll need to use that instance name
              in blemmo's examples above.
              • 4. Re: Rediculously dumb Actionscript question
                guttyguppygmail Level 1
                OK, thanks for the info. Here's what I'm doing:

                make a new flash movie
                draw a circle on the stage
                make the circle into a movie clip called ball
                name the instance ball
                double-click on ball to edit it on its own timeline
                add a stop action on frame 1
                insert a keyframe on frame 10
                drag the ball to the right on frame ten so its in a different place
                go back to the root timeline
                click on frame 1, type ball.play();
                test movie
                notice that the ball doesn't move, meaning it's not progressing past frame 1 of its timeline, even though you told it to play in the root timeline

                What am I missing?
                • 5. Re: Rediculously dumb Actionscript question
                  blemmo Level 1
                  That's because of the code execution order. Flash goes from the top level (the _root timeline) to the nested levels (the ball MC), and executes code in that order. So it first executes "ball.play()", then enters the ball timeline and executes "stop()". So the play() call doesn't do much here. It's good to keep that in mind, it's the same when you attach an MC that has code in it's first frame... can be really annoying.

                  So in this case, you could use ball.gotoAndPlay(2) instead, to play the ball MC right away.

                  greets,
                  blemmo
                  • 6. Rediculously dumb Actionscript question
                    guttyguppygmail Level 1
                    Thats it, thanks blemmo. Really though, this is one of many things I find difficult about the flash development environment. I mean, both timelines are running, right? So why isn't the stop code on the ball timeline being executed until I tell ball to play? It just seems couter-intuitive at times.

                    WOah, wait-

                    stop();
                    ball.gotoAndPlay(2);

                    doesn't do anything either. Darn!
                    • 7. Re: Rediculously dumb Actionscript question
                      blemmo Level 1
                      uhm, yep. Well, it seems it does execute the stop() in frame 1 of ball anyway when loading, so it stops the MC, but still goes to frame 2, because that was told in the main timeline. It's really not intuitive, but I guess it has some logic in it... it has to execute the code in frame 1 of the ball MC when the movie loads, but that is after the _root's code executes, which tells the MC to play the second frame. So it still executes the code from the main timeline, but only after the code in the MC's frame 1, resulting in a stop at frame 2.

                      Hm... not so sure if this is logical anymore... but I guess the Flash people had to decide on this execution order somehow, and accept the possible drawbacks, like this situation here.

                      If you add a frame in the main timeline and call ball.play() there, and it's doing as expected. I think it's just going wrong because it's all happening right at the initialisation of the movie.

                      hth,
                      blemmo
                      • 8. Re: Rediculously dumb Actionscript question
                        guttyguppygmail Level 1
                        So, I'm not dumb after all and you just can't do it that way lol? It seems strange that you can't do this...
                        • 9. Re: Rediculously dumb Actionscript question
                          Level 7
                          "guttyguppygmail" <webforumsuser@macromedia.com> wrote in message news:e4gf38$m2p$1@forums.macromedia.com...
                          > So, I'm not dumb after all and you just can't do it that way lol? It seems strange that you can't do this...

                          None of these problems apply if you use a preloader on your swfs. Preloaders make sure things are all loaded before just running
                          things willy-nilly whenever they happen to load.
                          If you make sure everything is loaded before you run your main timeline you will be all set and things will work. All the
                          movieclips with a stop command in frame 1 will be sitting there waiting at frame 1 for the instruction to start. The problem gets
                          worse once you upload your file to the Web because of the slowness of loading.
                          Except for the most simple projects, almost all swfs should have a preloader to get things started cleanly.
                          tralfaz


                          • 10. Re: Rediculously dumb Actionscript question
                            guttyguppygmail Level 1
                            Ok, I tried my ball example and added a simple preloader to it,and still the ball does not play. If you want to take a look at the fla file I made, it's here:
                            http://www.fieldii.com/test.fla.zip
                            I know I'm missing something fundamental about the way flash works,
                            • 11. Re: Rediculously dumb Actionscript question
                              Craig Grummitt Level 3
                              yeah flash can be a little unintuitive sometimes with the order it follows contradictory instructions(ie stop? gotoandplay? aaagh! how about gotoAndstop instead?).

                              here are three simple alternatives to get around this issue(and i'm sure there are many more)
                              1 - move the ball stop from the first frame to the second and gotoAndPlay 3.
                              2 - move the gotoandPlay on one frame so that the stop in ball has had a chance to do its thing before the playhead reaches the gotoandplay..
                              3 - put a play() on frame 2 of ball.

                              i'm afraid that wasn't really a preloader guttyguppygmail, it was a simple one off test that all assets were loaded. however a preloader doesn't appear to help this particular situation anyway tralfaz, although i think i know what you're talking about - going to a specific frame of the _root when it hasn't loaded yet causes problems.
                              • 12. Re: Rediculously dumb Actionscript question
                                Level 7
                                "Craig Grummitt" <webforumsuser@macromedia.com> wrote in message news:e4gt20$7m6$1@forums.macromedia.com...
                                > yeah flash can be a little unintuitive sometimes with the order it follows
                                > contradictory instructions(ie stop? gotoandplay? aaagh! how about gotoAndstop
                                > instead?).
                                >
                                > here are three simple alternatives to get around this issue(and i'm sure there
                                > are many more)
                                > 1 - move the ball stop from the first frame to the second and gotoAndPlay 3.
                                > 2 - move the gotoandPlay on one frame so that the stop in ball has had a
                                > chance to do its thing before the playhead reaches the gotoandplay..
                                > 3 - put a play() on frame 2 of ball.
                                >
                                > i'm afraid that wasn't really a preloader guttyguppygmail, it was a simple one
                                > off test that all assets were loaded. however a preloader doesn't appear to
                                > help this particular situation anyway tralfaz, although i think i know what
                                > you're talking about - going to a specific frame of the _root when it hasn't
                                > loaded yet causes problems.

                                I can't see the code because my Flash is version 6 but i've seen so many cases where a file just does funny stuff on startup because
                                things happened out of sequence. Preloaders that are written right usually fix that. They make it so that the main timeline
                                doesn't run any code actions on movieclips in the first frame and nothing gets activated until the preloader says everybody is
                                loaded. If I could see the swf I could find the problem me thinks.
                                tralfaz


                                • 13. Re: Rediculously dumb Actionscript question
                                  Craig Grummitt Level 3
                                  so you can replicate this issue yourself with Flash 6, here's what's contained in the fla:
                                  ---------------------------
                                  _root:
                                  Frame 1: "Preloader"
                                  stop();
                                  if(_framesloaded==_totalframes) {
                                  play();
                                  }

                                  Frame 2: (A movie clip on stage with instance name 'ball')
                                  stop();
                                  ball.play();
                                  --------------------------
                                  Ball Movie Clip:
                                  Frame 1:
                                  stop();

                                  Frames 1-15:
                                  Something to indicate movement or a change in frames
                                  • 14. Re: Rediculously dumb Actionscript question
                                    Level 7

                                    "Craig Grummitt" <webforumsuser@macromedia.com> wrote in message news:e4h4ba$f80$1@forums.macromedia.com...
                                    > so you can replicate this issue yourself with Flash 6, here's what's contained
                                    > in the fla:
                                    > ---------------------------
                                    > _root:
                                    > Frame 1: "Preloader"
                                    > stop();
                                    > if(_framesloaded==_totalframes) {
                                    > play();
                                    > }

                                    I know you are trying to help but you should know you can't run a preloader in one pass, you have to call it repeatedly.

                                    > Frame 2: (A movie clip on stage with instance name 'ball')
                                    > stop();
                                    > ball.play();

                                    You don't need to move it to frame 2.

                                    With the ball movieclip on frame 1 like it originally was..

                                    // a working preloader on frame 1 of main timeline..
                                    this.onEnterFrame = function()
                                    {
                                    var gbt = this.getBytesTotal();
                                    var gbl = this.getBytesLoaded();
                                    if (gbt && (gbl == gbt)) // not zero, and matching
                                    {
                                    delete this.onEnterFrame; // not needed anymore
                                    ball.play(); // start the ball
                                    }
                                    }

                                    It works fine, if you wait for the file to load before calling ball.play();
                                    tralfaz






                                    • 15. Re: Rediculously dumb Actionscript question
                                      Level 7
                                      > When you're dealing with objects, it's a lot like dealing with people:
                                      > just call your object by name and tell it what to do.

                                      Lol - someone obviously forgot to tell my wife and daughters that that's how
                                      people work )

                                      --
                                      -------------------------------
                                      Remove '_spamkiller_' to mail
                                      -------------------------------


                                      • 16. Re: Rediculously dumb Actionscript question
                                        Level 7
                                        Peter,

                                        >> When you're dealing with objects, it's a lot like dealing
                                        >> with people: just call your object by name and tell it
                                        >> what to do.

                                        > Lol - someone obviously forgot to tell my wife and
                                        > daughters that that's how people work )

                                        Ha. I was referring, actually, to my wife telling *me* what to do.
                                        :-p


                                        David
                                        stiller (at) quip (dot) net
                                        Dev essays: http://www.quip.net/blog/
                                        "Luck is the residue of good design."


                                        • 17. Re: Rediculously dumb Actionscript question
                                          Craig Grummitt Level 3
                                          i don't think you understood tralfaz - my previous post wasn't an attempt at a solution, it was merely explaining to you what was in guttyguppygmail's fla as you said you couldn't see the code as you had flash 6.

                                          "I know you are trying to help but you should know you can't run a preloader in one pass, you have to call it repeatedly."

                                          i know that this isn't a preloader which is why i put the word in quotation marks and said in an earlier post "i'm afraid that wasn't really a preloader..." and explained why.

                                          what you have done, tralfaz, is given flash at least a frame to activate the stop action in the circle clip, and then the ball.play() action in your preloader works fine. its not the preloader that is resolving this problem, it's the onEnterFrame. it would work just as well if you used the following script on frame 1(if the ball movieclip is on frame 1):

                                          this.onEnterFrame = function() {
                                          ball.play();
                                          };

                                          "You don't need to move it to frame 2."

                                          my point is that a preloader doesn't resolve this problem. what i'm interested to know is what your solution is if the circle movie clip is on frame 2.
                                          • 18. Re: Rediculously dumb Actionscript question
                                            Level 7
                                            "Craig Grummitt" <webforumsuser@macromedia.com> wrote in message news:e4qujf$pvc$1@forums.macromedia.com...
                                            >i don't think you understood tralfaz - my previous post wasn't an attempt at a
                                            > solution, it was merely explaining to you what was in guttyguppygmail's fla as
                                            > you said you couldn't see the code as you had flash 6.

                                            Oh, ok then. I misunderstood. I thought it was your code. Sorry.

                                            > what you have done, tralfaz, is given flash at least a frame to activate the
                                            > stop action in the circle clip, and then the ball.play() action in your
                                            > preloader works fine. its not the preloader that is resolving this problem,
                                            > it's the onEnterFrame. it would work just as well if you used the following
                                            > script on frame 1(if the ball movieclip is on frame 1):

                                            I have been through this before (years ago) and I can tell you that delaying by one frame may or may not work depending on the
                                            slowness off the loading. Combine a slow computer with a slow connection and you could have a malfunction. A long time ago I had
                                            been doing exactly what you said.. delaying the start of a clip until X number of frames but the results were not reliable with
                                            various browsers and connnections. A preloader makes sure it's ready regardless of the outside circumstances.
                                            Because I have a high speed connection, I would think that my flash project worked perfectly. Then when I was somewhere else and
                                            tried to show it to people on their slower connections the thing wouldn't run.. reason.. I was using the delay by frame method. I
                                            learned this the hard way! Now I use preloaders to be sure it will work.

                                            > this.onEnterFrame = function() {
                                            > ball.play();
                                            > };
                                            >
                                            > "You don't need to move it to frame 2."
                                            > my point is that a preloader doesn't resolve this problem. what i'm interested
                                            > to know is what your solution is if the circle movie clip is on frame 2.

                                            When the preloader is done you can play the main timeline. When it reaches the frame with the movieclip in it you can put
                                            ball.play() in a keyframe there.
                                            If you have a preloader in frame 1, it cannot directly address the ball in frame 2 because in frame 1, ball does not exist so the
                                            code doesn't assign correctly.

                                            Anyway, thanks for helping on the forum and sorry for the misunderstanding.
                                            'ave a gud 1
                                            tralfaz








                                            • 19. Re: Rediculously dumb Actionscript question
                                              Craig Grummitt Level 3
                                              sorry to labour this point, (you're probably sick of it by now!) but i'm still curious about this point and i'm still not sure you understand what i'm saying. maybe i'm not writing clearly - i'll try again.

                                              i completely understand the value of preloaders. i am not suggesting that the movie doesn't start until X number of frames. what i am saying is that in this case the problem seems to exist whether you have a preloader or not.

                                              i am not suggesting that after the preloader is loaded it tries to goto a frame in the circle mc (that would be just silly if the circle mc isn't on the stage yet). i was suggesting that the preloader would then navigate to a frame in the main timeline - let's call it frame 2.

                                              on this frame(2) the circle MC is introduced, which has a stop() on its first frame. ok now here's the problem - on the main timeline, if we were to write circle.play(), the circle would not play. if we were to write circle.gotoAndPlay(2) to attempt to get around that problem, the circle strangely goes to frame 2 and stops(!).
                                              • 20. Re: Rediculously dumb Actionscript question
                                                Level 7

                                                "Craig Grummitt" <webforumsuser@macromedia.com> wrote in message news:e4r9kh$85t$1@forums.macromedia.com...
                                                > i am not suggesting that after the preloader is loaded it tries to goto a
                                                > frame in the circle mc (that would be just silly if the circle mc isn't on the
                                                > stage yet). i was suggesting that the preloader would then navigate to a frame
                                                > in the main timeline - let's call it frame 2.
                                                >
                                                > on this frame(2) the circle MC is introduced, which has a stop() on its first
                                                > frame. ok now here's the problem - on the main timeline, if we were to write
                                                > circle.play(), the circle would not play. if we were to write
                                                > circle.gotoAndPlay(2) to attempt to get around that problem, the circle
                                                > strangely goes to frame 2 and stops(!).

                                                Yes, I understand what you mean.

                                                1) _root timeline says circle.play();
                                                2) circle movieclip frame 1 says stop();
                                                that cancels the play command from the _root before any screen updates occur.
                                                So, now why we can't have circle.gotoAndPlay(2) on the _root without still getting the stop() on frame 1 of the movieclip?
                                                Someone who knows more of the internal workings (like Jeckyl maybe) might be able to clear it up.

                                                FWIW If I were going to put the movieclip on frame 2 and have it play as soon as the timeline reached frame 2 I wouldn't put a stop
                                                on the movieclip frame 1 anyway. It will just start playing when it's instantiated.

                                                tralfaz





                                                • 21. Re: Rediculously dumb Actionscript question
                                                  blemmo Level 1
                                                  quote:

                                                  Originally posted by: Newsgroup User
                                                  1) _root timeline says circle.play();
                                                  2) circle movieclip frame 1 says stop();
                                                  that cancels the play command from the _root before any screen updates occur.
                                                  So, now why we can't have circle.gotoAndPlay(2) on the _root without still getting the stop() on frame 1 of the movieclip?



                                                  Same reason: because the code of circle executes after the code in _root, and the first appearance of circle is in the same frame. So it has to play frame 1 of circle and execute the stop(), which will stop the play part of gotoAndPlay(2).
                                                  It mixes up the time order here, I'd say. First is the code from _root followed by the code in circle's frame (which should be frame 2 now, without any code), but now there's still the code from frame 1 of circle to execute, because it was instantiated in that frame. So basically, the stop() of frame 1 overrides the _root action here, what I thought shouldn't be possible because of that code execution scheme...
                                                  Well, it's all just happening when the MC instantiates, so in other setups this shouldn't appear.
                                                  quote:


                                                  FWIW If I were going to put the movieclip on frame 2 and have it play as soon as the timeline reached frame 2 I wouldn't put a stop
                                                  on the movieclip frame 1 anyway. It will just start playing when it's instantiated.


                                                  Exactly.

                                                  Besides, in this setup here, a play() in frame 2 of circle would also do it, but even then, it would only work out when _root says gotoAndPlay(2), not frame 50 or any others. So it's definitely a wrong setup, with a stop() at a very wrong place.

                                                  greets,
                                                  blemmo
                                                  • 22. Re: Rediculously dumb Actionscript question
                                                    Level 7
                                                    > Same reason: because the code of circle executes after the code in _root, and
                                                    > the first appearance of circle is in the same frame. So it has to play frame 1
                                                    > of circle and execute the stop(), which will stop the play part of
                                                    > gotoAndPlay(2).
                                                    > It mixes up the time order here, I'd say. First is the code from _root
                                                    > followed by the code in circle's frame (which should be frame 2 now, without
                                                    > any code), but now there's still the code from frame 1 of circle to execute,
                                                    > because it was instantiated in that frame. So basically, the stop() of frame 1
                                                    > overrides the _root action here, what I thought shouldn't be possible because
                                                    > of that code execution scheme...
                                                    > Well, it's all just happening when the MC instantiates, so in other setups
                                                    > this shouldn't appear.

                                                    Sounds right to me blemmo. The main question in my mind was whether the movieclip's frame 1 code could be bypassed. It sounds like
                                                    that the code in frame 1 always executes during the instantiation whether you try to jump past it or not.
                                                    tralfaz


                                                    • 23. Re: Rediculously dumb Actionscript question
                                                      respondplease Level 1
                                                      Hi all,

                                                      Great post and info provided. After hours and hours of researching and a couple of posts that I received no feedback on (I'm aight....not offended...j/k!) I managed to figure out my AS:

                                                      on (release) {
                                                      instanceName.gotoAndPlay(2);
                                                      _root.gotoAndStop ("instanceName");
                                                      }

                                                      Just thought I'd share in hopes. Thanks again!!
                                                      • 24. Re: Rediculously dumb Actionscript question
                                                        Level 7
                                                        "respondplease" <webforumsuser@macromedia.com> wrote in message news:e51ujc$13u$1@forums.macromedia.com...
                                                        > Hi all,
                                                        >
                                                        > Great post and info provided. After hours and hours of researching and a
                                                        > couple of posts that I received no feedback on (I'm aight....not
                                                        > offended...j/k!) I managed to figure out my AS:
                                                        >
                                                        > on (release) {
                                                        > instanceName.gotoAndPlay(2);
                                                        > _root.gotoAndStop ("instanceName");
                                                        > }
                                                        >
                                                        > Just thought I'd share in hopes. Thanks again!!

                                                        Confused.. gotoAndStop doesn't work with instance names in the parens.. ("instancenames")
                                                        It can take a frame label there though.
                                                        tralfaz


                                                        • 25. Re: Rediculously dumb Actionscript question
                                                          respondplease Level 1
                                                          Tralfaz,

                                                          Actually you're right. Thanks for catching that!