-
Typing input text, and then dragging it. AS3
Hey, is it possible for a user to enter a frame, be able to type their name into an InputText field, and then drag it around the screen?
If so what is the best method to do this?
Thanks.
-
Yes, you can do that. Since TextFields don't have a startdrag method, you could simulate it with mousedown and mouseup handlers, or you could put the TextField into a containing Sprite and use startDrag on that Sprite.
-
Thanks for the input. Do you have a link to a tutorial by any chance? I'm still relatively new to Actionscript.
-
Here's a very basic example.
Code:
var textHolder:Sprite = new Sprite();
//draw a rectangular header dealy so they can click on something that isn't text
textHolder.graphics.beginFill(0x000000);
textHolder.graphics.drawRect(0, 0, 100, 5);
textHolder.graphics.endFill();
addChild(textHolder);
var tf:TextField = new TextField();
tf.type=TextFieldType.INPUT; //so they can write in it.
tf.y = 5;
textHolder.addChild(tf);
textHolder.addEventListener(MouseEvent.MOUSE_DOWN, startdragging);
textHolder.addEventListener(MouseEvent.MOUSE_UP, stopdragging);
function startdragging(e:MouseEvent):void{
textHolder.startDrag();
}
function stopdragging(e:MouseEvent):void{
textHolder.stopDrag();
}
-
Thanks, worked great.
Although sometimes after clicking a few times, the mouse cursor would become 'stuck' to the object, unable to let go.
Also I'm thinking if I were to attach a button to the InputTextfield, to say once clicked, transform the InputTextField into a dynamic textfield, is this possible? I think this would help as each time the text is clicked at the moment an option to edit the text is annoyingly in the way.
Thanks again.
-
I've found that 'sticky' behavior appears pretty much whenever you have a draggable. Not even just in flash. Application windows sometimes get it too.
You absolutely can have such a button, it's probably a good idea.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|