A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Typing input text, and then dragging it. AS3

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    6

    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.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  3. #3
    Junior Member
    Join Date
    Nov 2008
    Posts
    6
    Thanks for the input. Do you have a link to a tutorial by any chance? I'm still relatively new to Actionscript.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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();
    }

  5. #5
    Junior Member
    Join Date
    Nov 2008
    Posts
    6
    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.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center