• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Lesson 22. Optimizing Scripts > Using Parameters

Using Parameters

To work with the case structure you just built, you need to change the button scripts to call the MoveArm handler and send along information about what button was clicked. The call to the MoveArm handler will replace the code in each button script previously used to move the arm.

1.
In the Cast window, select cast member 28. Then click the Script button. Make the changes shown here in bold:

on mouseDown
  repeat while the mouseDown                --While the mouse button is held down
    if rollOver(2) = TRUE then              --and the mouse is over the Up button (sprite 2),
       sprite(2).memberNum = 29             --display the highlighted button state.
       MoveArm(1)
							--Call the MoveArm handler in the movie script
							--and send parameter 1.
    else                                    --Otherwise,
      sprite(2).memberNum = 28              --display the normal button state.
    end if
    updateStage                             --Update the stage to show changes.
  end repeat                                --The mouse button is no longer down,
  sprite(2).memberNum = 28                  --so return to the normal button state.
  updateStage                               --Update the stage to show changes.
end


					  

Now when this button is clicked, this script calls the MoveArm handler and sends a parameter of 1 to tell the MoveArm handler which case it should execute.

2.
In the Cast window, select cast member 30. Then click the Script button. Make the changes shown here in bold:

on mouseDown
  repeat while the mouseDown           --While the mouse button is held down
    if rollOver(3) = TRUE then         --and the mouse is over the Down button (sprite 3),
       sprite(3).memberNum = 31        --display the highlighted button state.
       MoveArm(2)
							--Call the MoveArm handler in the movie script
							--and send parameter 2.
    else                               --Otherwise,
      sprite(3).memberNum = 30         --display the normal button state.
    end if
    updateStage                        --Update the stage to show changes.
  end repeat                           --The mouse button is no longer down,
  sprite(3).memberNum = 30             --so return to the normal button state.
  updateStage                          --Update the stage to show changes.
end


					  

When this button is clicked, it calls the MoveArm handler and sends a parameter of 2 to tell the MoveArm handler to execute case 2.

3.
In the Cast window, select cast member 32. Then click the Script button. Make the changes shown here in bold:

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.
      MoveArm(3)
							--Call the MoveArm handler in the movie script
							--and send parameter 3.
    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


					  

4.
In the Cast window, select cast member 34. Then click the Script button. Make the changes shown here in bold:

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.
       MoveArm(4)
							--Call the MoveArm handler in the movie script
							--and send parameter 4.
    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.
Close the Script window, save your work, and play the movie.

It works! All the buttons should still be active and working correctly.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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