您好我想知道如何使用文本字段,用户可以通过在Flash中点击并拖动来更改尺寸?
即。电影会显示一个带有变换手柄的文本字段,并根据它改变自动换行的宽度或高度来实现..
这可能吗? 干杯, 汤姆
答案 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;
}