9 Replies Latest reply on Aug 1, 2008 10:57 AM by Newsgroup_User

    Controling Flash Sprites with Lingo

    rossimo Level 1
      I need to control a Flash sprite with in Director so that when the user pushed a stop button, both the Director and Flash playheads stop.

      I have attached this code to a button without success.
      ---------
      on click
      sprite(1).stop()
      go to the frame
      end
      ---------

      My thoughts were I would need to stop the Flash playhead with the "sprite(1).stop()" and the Director playhead with "go to the frame". I am coming over from a Flash background, so thank you for any and all help!

      |rossimo|

        • 1. Controling Flash Sprites with Lingo
          rossimo Level 1
          UPDATE:

          I have had success with controlling my Flash sprite with play and stop in Lingo: Here is my updated code:

          Stop Button
          ----------------------
          on mouseUp me
          sprite(1).stop()
          end


          Play Button
          ----------------------
          on mouseUp me
          sprite(1).play()
          end

          Now the only remaining problem is how, using Lingo, can I stop and start the Director playhead? With the code above my Flash sprite stops playing, but the Director playhead keeps going. I have a frame event to send the view to another movie when the Flash sprite hits the end. As it is now, if I pause the Flash sprite, the user gets kicked out to the next movie before they should.

          Thanks for any help!-
          |rossimo|
          • 2. Re: Controling Flash Sprites with Lingo
            Ex Malterra Level 1
            As near as I can figure Director never really stops in the same way Flash does; in Flash the movie is still playing even if the playhead isn't moving. Even if you call stop() the Flash movie is still "going', alive and running, the frame just isn't being entered again. Not so in Director. The playhead is perpetually moving as long as a call to _player.quit() hasn't been made, or the user hasn't closed the file. You have to use _movie.go(_movie.frame) or one of the other "go" methods to keep looping on the frame you want to enter. But, the prepareFrame, enterFrame and exitFrame events are constantly being triggered based on the specified frame rate, or at least as close to the frame rate that the computer can deliver.

            Again, that's just my understanding of what's going on under the hood. I hope I'm not spreading false information! Maybe others can provide better info.
            • 3. Re: Controling Flash Sprites with Lingo
              Level 7
              I suspect that you are monitoring the Flash sprite for "completion" by
              polling its 'playing' status, and since you have explicitly told it to
              stop(), sprite.playing evaluates to FALSE. You could move to comparing
              the currentFrame against the totalFrames - which will more readily tell
              you whether it's finished (although, if it's animating in a contained
              movieClip, you will need to monitor this instead of _root)
              • 4. Re: Controling Flash Sprites with Lingo
                Level 7
                'go the frame' only happens once per event. It does not actually stop the
                playhead, but tells director to go to this frame again rather than on to the
                next - once. If you want Director's playhead to stay in one frame, you'll
                need repeatedly issue the command. exitFrame is a good place for that to
                happen.

                on exitFrame me
                go the frame
                end

                Every time the exitFrame event fires, it is told to go to the same frame
                again. Lather, rinse, repeat.

                Since you already have a frame event running (exitFrame?), you may want to
                set a global variable flag that can be detected during this event. Perhaps
                something like the following:

                Stop Button
                ----------------------
                global gPaused
                on mouseUp me
                sprite(1).stop()
                gPaused = 1
                end


                Play Button
                ----------------------
                global gPaused
                on mouseUp me
                sprite(1).play()
                gPaused = 0
                end

                Frame event
                ----------------------
                global gPaused
                on exitFrame me
                if gPaused then
                go the frame
                else
                -- what ever you're using to send
                -- to another movie when Flash ends.
                end if
                end




                --
                Mark A. Boyd
                Keep-On-Learnin' :)
                • 5. Re: Controling Flash Sprites with Lingo
                  rossimo Level 1
                  Thank you Ex Malterra, Sean and Mark — I will check out out the help and advice you have given me and report back.

                  Thanks-
                  |rossimo|
                  • 6. Re: Controling Flash Sprites with Lingo
                    rossimo Level 1
                    Mark-

                    I tried out your solution and it works exactly as you stated. It helped out a lot, thank you. However, I think I am going to need to combine your solution with Sean's solution. I have animation and voice narration in my Flash sprite. When I use your (Mark) solution if I hit "play button" after being stopped for awhile I am still shifted off the Flash timeline and I am prematurely sent to the next movie before the current Flash sprite is completed.

                    I do think I am going to need to run an if then statement to check played frames in my Flash sprite against the total amount of frames and when they are equal (meaning the end of the Flash sprite) then send the user to the next movie.

                    Sean or Mark (or anyone else), do you know of how I should code this? Or know of a tutorial online I can check out? I am really eager to learn more Lingo. Thanks again!

                    |rossimo|
                    • 7. Re: Controling Flash Sprites with Lingo
                      Level 7
                      rossimo posted in macromedia.director.lingo:

                      > I do think I am going to need to run an if then statement to check
                      > played
                      > frames in my Flash sprite against the total amount of frames and when
                      > they are equal (meaning the end of the Flash sprite) then send the user
                      > to the next movie.

                      Probably.

                      > Sean or Mark (or anyone else), do you know of how I should code this?

                      Show us the Lingo you're using now. As you say, it should be as simple as
                      adding an if/then condition. But we can't really help much without seeing
                      your code.



                      --
                      Mark A. Boyd
                      Keep-On-Learnin' :)
                      • 8. Re: Controling Flash Sprites with Lingo
                        rossimo Level 1
                        Many thanks to Sean and Mark! You guys really helped me to arrive at my solution.

                        Here is the final code for the End Frame:
                        -------------------------
                        on exitFrame me
                        CF = sprite(1).getFlashProperty("", #currentFrame)
                        TF = sprite(1).getFlashProperty("", #totalFrames)
                        if CF < TF then
                        go the frame
                        else
                        go to frame ("Menu")
                        end if
                        end
                        -------------------------

                        This in conjunction with the Play and Stop buttons (listed in the thread) is giving me exactly what I need. This way when I pause the Flash sprite it will not go to my Menu marker until currentFrame is greater than totalFrames. I guess I could also use a greater than or equal to, but this is working in my scene.

                        Thanks again for all of your help!-
                        |rossimo|
                        • 9. Re: Controling Flash Sprites with Lingo
                          Level 7
                          Hmm. It seems as though your script should work without the gPause flag I
                          proposed. Are you sure there isn't another script causing it to go to "Menu"?

                          I see you're setting TF in every exitFrame. No need for that, try setting a
                          property variable once in a beginSprite event. I don't know if it will affect
                          it, but worth a try.

                          -------------------------
                          property pTF
                          on beginSprite me
                          pTF = sprite(1).getFlashProperty("", #totalFrames)
                          end
                          on exitFrame me
                          CF = sprite(1).getFlashProperty("", #currentFrame)
                          if CF < pTF then
                          go the frame
                          else
                          go to frame ("Menu")
                          end if
                          end
                          -------------------------

                          If those don't work, here's a method with the gPaused flag.
                          -------------------------
                          global gPaused
                          property pTF
                          on beginSprite me
                          pTF = sprite(1).frameCount
                          end
                          on exitFrame me
                          if NOT gPaused then
                          if sprite(1).currentFrame >= pTF then
                          go to "Menu"
                          end if
                          end if
                          go the frame
                          end
                          -------------------------

                          I still think it should work without the gPaused flag, though. I mean, if the
                          Flash sprite is stopped, it's hardly likely to be stopped precisely on the
                          last frame.

                          Note: I can't get to Director from this machine, so all of the above is
                          untested code. Also, I seem to recall getting the properties directly from
                          the Flash sprites as seen in my last example - and using frameCount rather
                          than totalFrames.

                          If that doesn't work, try detecting pTF and currentFrame with your previous
                          method.

                          Is there a pause() continue() function for Flash sprites? Again, sorry that I
                          can't get to Director right now.



                          --
                          Mark A. Boyd
                          Keep-On-Learnin' :)