03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

You must first create a generic object that has two properties, x <strong>and</strong> y. These x <strong>and</strong> y values<br />

(<strong>and</strong> they must be called x <strong>and</strong> y) are called the global coordinates because they relate to the<br />

top-left corner of the Stage. The x property represents the horizontal offset from the top-left<br />

corner. In other words, it represents how far to the right the point lies. For example, if x = 50,<br />

the point lies 50 pixels to the right of the top-left corner. The y property represents the vertical<br />

offset from the top-left corner. In other words, it represents how far down the point lies. For<br />

example, if y = 20, the point lies 20 pixels below the top-left corner. The following code<br />

creates a generic object with these coordinates:<br />

var myPoint:Object = new Object();<br />

myPoint.x = 50;<br />

myPoint.y = 20;<br />

Alternatively, you can create the object <strong>and</strong> assign the values at the same time with a literal<br />

Object value:<br />

var myPoint:Object = {x:50, y:20};<br />

After you create a point object with global coordinates, you can convert the coordinates to<br />

local coordinates. The globalToLocal() method doesn't return a value because it changes<br />

the values of x <strong>and</strong> y in the generic object that you send as the parameter. It changes them<br />

from values relative to the Stage (global coordinates) to values relative to a specific movie clip<br />

(local coordinates).<br />

For example, if you create a movie clip that is positioned at the point (_x:100, _y:100), <strong>and</strong><br />

you pass the global point representing the top-left corner of the Stage (x:0, y:0) to the<br />

globalToLocal() method, the method should convert the x <strong>and</strong> y values to the local<br />

coordinates, which in this case is (x:-100, y:-100). This is because the x <strong>and</strong> y coordinates<br />

are now expressed relative to the top-left corner of your movie clip rather than the top-left<br />

corner of the stage. The values are negative because to get from the top-left corner of your<br />

movie clip to the top-left corner of the Stage you have to move 100 pixels to the left (negative<br />

x) <strong>and</strong> 100 pixels up (negative y).<br />

The movie clip coordinates were expressed using _x <strong>and</strong> _y, because those are the MovieClip<br />

properties that you use to set the x <strong>and</strong> y values for MovieClips. However, your generic object<br />

uses x <strong>and</strong> y without the underscore. The following code converts the x <strong>and</strong> y values to the<br />

local coordinates:<br />

var myPoint:Object = {x:0, y:0}; // Create your generic point object.<br />

this.createEmptyMovieClip("myMovieClip", this.getNextHighestDepth());<br />

myMovieClip._x = 100; // _x for movieclip x position<br />

myMovieClip._y = 100; // _y for movieclip y position<br />

myMovieClip.globalToLocal(myPoint);<br />

trace ("x: " + myPoint.x); // output: -100<br />

trace ("y: " + myPoint.y); // output: -100<br />

MovieClip 433

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!