用鼠标移动文本字段

时间:2014-02-02 12:19:37

标签: actionscript-3 flash textbox

这是我在单击按钮时创建文本框的代码:

TextBoxButton.addEventListener(MouseEvent.CLICK, addTextBox);

function addTextBox(e:MouseEvent):void
{
    myFont = new Font2();
    typeText:TextField = new TextField();
    typeText.defaultTextFormat = myFormat;
    ttypeTextext.x = 540;
    typeTexteText.width = 175;
    ttypeTextText.type = TextFieldType.INPUT;
    typeTexteText.text = "Your text here";

    //Adding to the stage.
    newLayer.addChild(typeableText);
}

我的问题是:如何修改此代码,以便用户可以使用鼠标将文本拖放到舞台上的任何位置?

编辑:一些进一步的代码:

TextBoxButton.addEventListener(MouseEvent.CLICK, addTextBox);

function addTextBox(e:MouseEvent):void
{
    var myFont = new Font2();
    var typeableText:TextField = new TextField();
    typeableText.defaultTextFormat = myFormat;
    typeableText.antiAliasType = AntiAliasType.ADVANCED;
    typeableText.embedFonts = true;
    typeableText.x = 540;
    typeableText.y = 400;
    typeableText.width = 175;
    typeableText.height = 200;
    typeableText.wordWrap = true;
    typeableText.type = TextFieldType.INPUT;
    typeableText.text = "Your text here";
    interfaceLayer.buttonMode = true;
    //Adding to the stage.
    appLayer.addChild(typeableText);
    if (typeableText.stage)
    {
        SideBarText.removeChild(TextBoxButton);
    }
}

appLayer.addEventListener(MouseEvent.MOUSE_DOWN, dragText);
appLayer.addEventListener(MouseEvent.MOUSE_UP, stopDragText);

function dragText(e:MouseEvent):void
{
    appLayer.startDrag();
}

function stopDragText(e:MouseEvent):void
{
    appLayer.stopDrag();
}

0 个答案:

没有答案