Properties
Mouse position
There is one interesting pair of properties, which allow to trace position of the mouse on the screen. So Flash file may know where the mouse cursor is located. It may be very useful in interactive application creation. For now we'll create a small example- Open a new file and set a fairly large stage (for example 500X500px)
- Create a movie symbol of anything you want. In our example it's a circle. Give it's instance on the stage a name (in our example - "ball")
- Create a movie symbol of . Anything actually it can be something invisible. In our example it's a small red rectangle in the middle of the stage. We need it as our coordinate anchor. Give it an instance name (in our example "rectangle").
- Enter the following code in the only frame of this movie . Pay attention it must be a frame not any of movie clips.
rectangle.onMouseMove = function(){ ball._xscale = rectangle._xmouse/2+30; ball._yscale = rectangle._ymouse/2+30; ball._alpha = rectangle._ymouse/3+100; } - Analyze the code. Our anchor instance "rectangle" watches moving the mouse and always know the mouse coordinates. When MouseMove event repeatedly happen such parameters of ball as _xscale, _yscale and change and their values are assigned dependently on mouse position. We divide those values and add 30 or 100 to adjust this changes to the symbol and stage size. You may experiment with those values. We also added the code to change _alpha to illustrate the concept.
- Test movie. If you placed the anchor symbol (like our "rectangle" ) in the middle of the stage, then _xmouse and _ymouse will receive negative values. It leads to "negative" size of the "ball" symbol and it will be turned "inside-out".
- When working with symbols be aware that their "internal coordinates" have 0 point not in the left top corner as the stage, but at their "anchor point" which look like a cross when you edit symbol. You may move drawings inside the symbol to adjust anchor point whenever you want.