0
votes

Hi I was wondering how I'd go about having a text field a user can change the dimensions of by clicking and dragging in Flash?

i.e. the movie would show a text field with transform handles and depending on how wide or high it changes the word wrap..

Is this possible? Cheers, Tom

1

1 Answers

1
votes

Here's an example:

import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;

var textfield:TextField;
var handle:Sprite;

textfield = new TextField();
textfield.wordWrap = true;
textfield.border = true;
textfield.background = true;
textfield.text = "lorem ipsum dolor sit amet"

handle = new Sprite();
handle.graphics.beginFill(0x000000);
handle.graphics.drawRect(0, 0, 10, 10);
handle.graphics.endFill();

handle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
handle.x = textfield.x + textfield.width;
handle.y = textfield.y + textfield.height;

addChild(textfield);
addChild(handle);

function mouseDownHandler(event:MouseEvent):void
{
    handle.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    handle.addEventListener(Event.ENTER_FRAME, frameHandler);
    handle.startDrag(false);
}

function mouseUpHandler(event:MouseEvent):void
{
    handle.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    handle.removeEventListener(Event.ENTER_FRAME, frameHandler);
    handle.stopDrag();
}

function frameHandler(event:Event):void
{
    textfield.width = handle.x - textfield.x;
    textfield.height = handle.y - textfield.y;
}