Swapping the Mouse Pointer


To make it obvious where on the island the tank could be moved, I used several new Flash 5 features to swap the default mouse pointer for a custom icon.

Exercise 25.1 Creating a Custom Mouse Pointer

  1. Create a new movie clip, which will replace the default mouse pointer. It can be any shape and size .

  2. Drag an instance of the bullseye movie clip to the work area, but place it outside the stage so that it will be out of the way. Set the instance name to bullseye.

  3. To detect whether the mouse is positioned over the player1target movie clip, use the hitTest() function inside an onClipEvent(enterFrame) event on any movie clip (I put it on the player1target symbol for this project):

     onClipEvent(enterFrame) {     if (_root.player1target.hitTest(_root._xmouse, _root._ymouse,      true)) {     }  } 
  4. To make the default mouse pointer invisible, insert Flash 5's new Mouse() object inside the if statement:

     Mouse.hide(); 
  5. Tell the bullseye movie clip to start tracking the mouse pointer location by inserting the startDrag() function inside the if statement:

     startDrag("_root.bullseye", true); 
  6. To make the bullseye movie clip visible, modify its _visible property by adding the following:

     _root.bullseye._visible = true; 

    Note

    It is possible to hide a movie clip by setting the Alpha to 0% in the Effect panel or by setting its _alpha property. However, it's better to set the _visible property to false if you want the movie clip to be fully invisible because setting the _alpha property requires more processing cycles.

  7. To swap the mouse pointer back to the original when the mouse is no longer over the player1target movie clip, add the following code inside the onClipEvent(enterFrame) event (see Figure 25.2):

     else {         _root.bullseye._visible = false;          stopDrag;          Mouse.show();      }  } 
    Figure 25.2. When the mouse is positioned over the player1target or player2target movie clips, the mouse pointer is swapped with the bullseye movie clip.

    graphics/25fig02.gif

Note

Vector graphics require significantly more CPU cycles to display than bitmap graphics. This is especially true as the animations get more complex.

An onClipEvent(enterFrame) event will execute repeatedly as long as a movie clip is on the stage. This puts a tremendous load on the CPU and should be avoided except when necessary. This movie is set to play 18 frames per second, and most computers will be noticeably sluggish when playing this game because of the numerous onClipEvent(enterFrame) events throughout the movie. You can improve performance somewhat by attaching and then removing movie clips that use an onClipEvent(enterFrame) event from the stage when they are not being used. Any time an onClipEvent(enterFrame) is being executed repeatedly, there is an enormous strain on the processor.




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