• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Calling the Handlers

In this next task, you will add scripts that call the handlers you just wrote.

1.
In the Cast window, select the Extend button (cast member 32). Then click the Script button to open the Script window.

This script already contains the handler that displays the normal and highlighted states of the button.

2.
Add the line shown here in bold and then close the window.

on mouseDown
  repeat while the mouseDown          --While the mouse button is held down
    if rollOver(4) = TRUE then        --and the mouse is over the EXTEND button (sprite 4),
       sprite(4).memberNum = 33       --display the highlighted button state.
       ExtendArm()
							--Call the ExtendArm handler in the movie script.
  else                                --Otherwise,
      sprite(4).memberNum = 32        --display the normal button state.
  end if
    updateStage                       --Update the stage to show changes.
  end repeat                          --The mouse button is no longer down,
  sprite(4).memberNum = 32            --so return to the normal button state.
  updateStage                         --Update the stage to show changes.
end


					  

3.
In the Cast window, select the Retract button (cast member 34). Then click the Script button to open the Script window.

This script already contains the handler that displays the normal and highlighted states of the button.

4.
Add the line shown here in bold and then close the window.

on mouseDown
  repeat while the mouseDown         --While the mouse button is held down
    if rollOver(5) = TRUE then       --and the mouse is over the RETRACT button (sprite 5),
        sprite(5).memberNum = 35     --display the highlighted button state.
       RetractArm( )
							--Call the RetractArm handler in the movie script.
    else                             --Otherwise,
       sprite(5).memberNum = 34      --display the normal button state.
    end if
    updateStage                      --Update the stage to show changes.
  end repeat                         --The mouse button is no longer down,
  sprite(5).memberNum = 34           --so return to the normal button state.
  updateStage                        --Update the stage to show changes.
end


					  

5.
Save your work.

Now you have a movie script that contains the ExtendArm and RetractArm handlers. You also have a cast script attached to the Extend button that calls the ExtendArm handler in the movie script, and you have a similar cast script attached to the Retract button that calls the RetractArm handler in the movie script.

6.
Play the movie and click all the buttons. Stop the movie when you're done.

Good work! All the buttons should now be active and working correctly.

Swapping sprites like this is a great technique for displaying different versions of cast members. Remember that the cast has been arranged so that the fully extended arm is at one end of the sequence and the fully retracted arm is at the other end. Planning ahead and arranging the cast makes this type of animation using Lingo easier.

Think about how you might create this project in the score only. Consider a simplified example: Suppose the arm can move up only 4 pixels and can extend using only four cast members. Identify these as pixel1, pixel2, pixel3, pixel4, cast1, cast2, cast3, and cast4, respectively. Assume that the arm starts at location pixel1 using cast1. This means you would need a frame in the score to display this instance of cast1 at location pixel1. If you were to click the Up button, cast1 would move to pixel2. That means you would need to create a frame in the score showing cast1 at location pixel2. Suppose you then click the Extend button; you would need a frame in the score showing cast2 at location pixel2. Suppose you click the Extend button again; you would need a frame in the score showing cast3 at location pixel2.

As you can see, the potential combinations are staggering, even for this small example, and developing handlers to deal with each and every situation would be quite difficult. Using Lingo instead of the score is often a much simpler solution than trying to develop handlers for all instances of possible combinations in the score that your project might require.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint