Hi,
I am trying to figure out the best way to drag dynamic TextField objects. You can't use startDrag() directly on text so I've been messing around with trying to put the text inside a Sprite...no luck though. Here is an example of one thing I was trying. The rectangle was just a visual and something to drag. It is the closest thing I have to working. I am definitely missing something here. I'd really appreciate a kick in the right direction on dragging text around.
Code:
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class ExampleApplication extends Sprite {
var MyText:TextField = new TextField();
var MyRectangle:Sprite = new Sprite();
public function ExampleApplication() {
MyText.text = "Hello.";
MyText.x = 30;
MyText.y = 20;
MyText.selectable = false;
MyRectangle.graphics.lineStyle();
MyRectangle.graphics.beginFill(0xFF0000);
MyRectangle.graphics.drawRect(0, 0, 100, 50);
MyRectangle.graphics.endFill();
MyRectangle.x = 50;
MyRectangle.y = 75;
addChild(MyRectangle);
MyRectangle.addChild(MyText);
MyRectangle.addEventListener(MouseEvent.MOUSE_DOWN, pickup);
MyRectangle.addEventListener(MouseEvent.MOUSE_UP, place);
}
public function pickup(event:MouseEvent):void {
event.target.startDrag(false);
}
public function place (event:MouseEvent):void {
event.target.stopDrag();
}
}
}