FLASH - 用户添加/转换的文本字段

时间:2011-08-04 07:04:48

标签: flash flex actionscript air

您好我想知道如何使用文本字段,用户可以通过在Flash中点击并拖动来更改尺寸?

即。电影会显示一个带有变换手柄的文本字段,并根据它改变自动换行的宽度或高度来实现..

这可能吗? 干杯, 汤姆

1 个答案:

答案 0 :(得分:1)

以下是一个例子:

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;
}