9 Replies Latest reply: Apr 28, 2012 9:22 AM by bmohnsen RSS

    Creating own controller

    bmohnsen

      There are parts of my movie where I want the user to have complete control. So I created a controller with step back, pause, step forward, play.

       

      Any help with script would be appreciate. I have tried go to the frame for stop --- and even put it in a loop - but it doesn't stop

       

      I have tried frame+1 for step forward without any lock.

       

      How do control frame movement.

       

      I would prefer not to use markers - because the count would be in the thousands.

       

      Thanks

        • 1. Re: Creating own controller
          SeanWilson Community Member

          When you say

          I have tried go to the frame for stop --- and even put it in a loop - but it doesn't stop

          are you talking about your Director movie or a video file you have playing on the stage?

          • 2. Re: Creating own controller
            bmohnsen Community Member

            Director movie

            • 3. Re: Creating own controller
              SeanWilson Community Member

              And so you're wanting a controller something like the QuickTime controller, with a play/apuse button and a sliding scrub bar?

              • 4. Re: Creating own controller
                bmohnsen Community Member

                Yes - thank you

                • 5. Re: Creating own controller
                  Production Monkey Community Member

                  One way to approach this is to place all the logic for controling the position of the timeline in a parent script and then use a global exitFrame handler inside a movie script to route the call to an instance of the parent script.

                   

                  It's simpler than it sounds.

                   

                  Here's the movie script:

                   

                  global gControler

                   

                  on prepareMovie

                    gControler = script("Timeline Controler").new(#play)  -- #play, #pause, #reverse. [speed] optional speed value

                  end

                   

                   

                  on exitFrame

                    gControler.updateFrame() 

                  end

                  --------------------------------------------------------

                   

                  Now you can control the flow of the timeline via the global object "gControler" which I provide below.

                   

                  The interface is:

                   

                  gControler.play(), gControler.play(3), etc

                  gControler.reverse(), gControler.reverse(2), etc

                  gControler.pause()

                  gControler.jump(1), gControler.jump(10), etc

                  gControler.seek(10), gControler.seek(1000), etc

                   

                   

                  Any exitFrame handlers in FrameScripts will override the movieScript exitframe handler. Which you may or may not want to do.

                   

                  Paste the following in to a parent script named: "Timeline Controler"

                   

                  -- Parent Script Timeline Controler

                   

                   

                  property  pState  -- #play, #pause, #reverse

                  property  pSpeed  -- frames per exitFrame. Normal play rate is 1.

                   

                   

                  on new me, aState, speed

                    if aState.SymbolP then

                      pState = aState

                    else

                      pState = #play

                    end if

                   

                    if Not [#play, #pause, #reverse].getPos(pState) then pState = #play

                   

                    if speed.IntegerP then

                      pSpeed = speed

                    else

                      pSpeed = 1

                    end if

                   

                    return me

                  end new

                   

                   

                  -- change current frame based on state variable pState

                  on updateFrame me

                    case pState of

                      #play:       go(min(_movie.frame + pSpeed, _movie.lastframe))

                       

                      #reverse:  go(max(1, _movie.frame - pSpeed))

                       

                      #pause:    go(_movie.frame)

                       

                    end case

                  end updateFrame

                   

                   

                  -- go forwards

                  on play me, speed

                    if speed.IntegerP then

                      pSpeed = speed

                    else

                      pSpeed = 1

                    end if

                   

                    pState = #play

                  end play

                   

                   

                  -- go backwards

                  on reverse me, speed

                    if speed.IntegerP then

                      pSpeed = speed

                    else

                      pSpeed = 1

                    end if

                   

                    pState = #reverse

                  end reverse

                   

                   

                  -- loop on a frame

                  on pause me

                    pState = #pause

                  end pause

                   

                   

                  -- move "pos" number of frames from current position. Can be positive or negative

                  on jump me, pos

                    if pos.IntegerP then

                      go(max(1, min(_movie.frame + pos, _movie.lastframe)))

                    end if

                  end jump

                   

                   

                  -- go to an absolute position on the timeline

                  on seek me, pos

                    if pos.IntegerP then

                      go(max(1, min(pos, _movie.lastframe)))

                    end if

                  end seek

                  • 6. Re: Creating own controller
                    bmohnsen Community Member

                    Wow - thank you so much

                    • 7. Re: Creating own controller
                      bmohnsen Community Member

                      on prepareMovie

                        gControler = script("Timeline Controler").new(#play)  -- #play, #pause, #reverse. [speed] optional speed value

                      end

                       

                      Do you create

                       

                      gControler = script("Timeline Controler").new(#play)

                       

                       

                      for pause and reverse as well?

                       

                      gControler = script("Timeline Controler").new(#pause)

                      gControler = script("Timeline Controler").new(#reverse)

                      • 8. Re: Creating own controller
                        bmohnsen Community Member

                        I am getting an object expected error.

                         

                        Here is the code I have in my movie script

                         

                        global gControler

                         

                        on prepareMovie

                          gControler = script("Timeline Controler").new(#play)

                        end

                         

                        on exitFrame

                          gcontroler.updateFrame()

                        end

                         

                         

                         

                        ==

                        Then I used the code you gave me and put it in a parent script.

                         

                         

                        ==

                        Then I created four buttons - back, pause, play, forward

                         

                        Back:

                        global gControler

                         

                        on mouseEnter()

                          cursor 280

                        end mouseEnter

                         

                        on mouseLeave()

                          cursor -1

                        end mouseLeave

                         

                         

                        on mouseup

                         

                          gControler.reverse(1)

                        end

                         

                         

                        Play:

                        global gControler

                         

                        on mouseEnter()

                          cursor 280

                        end mouseEnter

                         

                        on mouseLeave()

                          cursor -1

                        end mouseLeave

                         

                         

                        on mouseup

                         

                          gControler.play()

                        end

                         

                         

                         

                        Forward:

                        global gControler

                         

                        on mouseEnter()

                          cursor 280

                        end mouseEnter

                         

                        on mouseLeave()

                          cursor -1

                        end mouseLeave

                         

                         

                        on mouseup

                         

                          gControler.play(1)

                        end

                         

                         

                         

                        Pause:

                        global gControler

                         

                        on mouseEnter()

                          cursor 280

                        end mouseEnter

                         

                        on mouseLeave()

                          cursor -1

                        end mouseLeave

                         

                         

                        on mouseup

                         

                          gControler.pause()

                        end

                        • 9. Re: Creating own controller
                          bmohnsen Community Member

                          Got it

                           

                          had to just gControler.jump