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.

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

global coordinates. The localToGlobal() 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 a specific movie clip (local coordinates) to values relative to the Stage<br />

(global 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 a local point representing a point near the top-left corner of the movie clip (x:10,<br />

y:10) to the localToGlobal() method, the method should convert the x <strong>and</strong> y values to<br />

global coordinates, which in this case is (x:110, y:110). This conversion occurs because the x<br />

<strong>and</strong> y coordinates are now expressed relative to the top-left corner of the Stage rather than the<br />

top-left corner of your movie clip.<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 coordinates to<br />

global coordinates:<br />

var myPoint:Object = {x:10, y:10}; // 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.localToGlobal(myPoint);<br />

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

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

You can extend the methods <strong>and</strong> event h<strong>and</strong>lers of the MovieClip class by creating a subclass.<br />

Parameters<br />

pt:Object - The name or identifier of an object created with the Object class, specifying the<br />

x <strong>and</strong> y coordinates as properties.<br />

Example<br />

The following example converts x <strong>and</strong> y coordinates of the my_mc object, from the movie clip's<br />

(local) coordinates to the Stage (global) coordinates. The center point of the movie clip is<br />

reflected after you click <strong>and</strong> drag the instance.<br />

this.createTextField("point_txt", this.getNextHighestDepth(), 0, 0, 100,<br />

22);<br />

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

mouseListener.onMouseMove = function() {<br />

var point:Object = {x:my_mc._width/2, y:my_mc._height/2};<br />

my_mc.localToGlobal(point);<br />

point_txt.text = "x:"+point.x+", y:"+point.y;<br />

};<br />

MovieClip 445

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

Saved successfully!

Ooh no, something went wrong!