Clicking the Island to Move the Tank


To control where the tanks can move, I used Flash 5's new built-in hitTest() function, which checks to see whether a movie clip overlaps with specific coordinates or another movie clip. The function's third argument is a Boolean value that specifies whether to evaluate only the actual area occupied by the symbol rather than the symbol's rectangular bounding box. I created a new Player 1 target button that was slightly smaller than the left half of the island. The Player1 target button had to be smaller than the area where the tank was allowed to move because it is the center point (rather than the edges) of the tank symbol that is moved to where the player clicks the mouse. I moved the shape into the Hit frame for the button so that it would be invisible. The hitTest() function could not find the Player 1 target symbol because it did not have an instance name. I changed it to a movie clip and set the variable name to player1target. To hide the target, I moved the targets layer below the islands layer.

To check whether the mouse pointer is on top of the player1target movie clip when the mouse is clicked, I placed the following code onto the player1tank movie clip:

 onClipEvent(mouseDown) {     if (_root.player1target.hitTest(_root._xmouse, root._ymouse, true)) {         trace("player 1's target clicked");      }  } 


Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net