Thursday, April 8, 2010

AS 3.0 : Primer on Global To Local

Today's Nyum-nyum codes will give you a head start with:

Constraining your object/mouse as a slider
You may copy and paste the following into the first frame of your timeline.

//1. import this flash class at the very top...
import flash.geom.Point;

//2. Define a 'constraining' area...I'm making a vertical slider, hence the following coordinates
var myVerRect:Rectangle=new Rectangle(50,200,1,200);

//3. Tell Flash to find the relative distance between your dragged object, in this case a slider handle and the point of origin

MyTextField.text=nameOfClipBeingDragged.globalToLocal(new Point(specifyXPOS,specifyYPOS)).y


//4. Start Drag Action
nameOfClipBeingDragged.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
function Drag(myEvent:MouseEvent):void {
myEvent.target.startDrag(true,myVerRect);
trace(MyTextField.text);
}


No comments:

Post a Comment