StageText的。如何在变量中存储用户输入?

时间:2012-09-01 03:13:16

标签: actionscript-3 air

我有一个在我的手机上工作的stageText对象。我可以输入字段并显示文本。如何捕获输入文本并将其存储在变量中以供以后使用?谢谢。

var qatAccessCode:StageText = new StageText();
qatAccessCode.softKeyboardType = SoftKeyboardType.NUMBER;
qatAccessCode.restrict = "0-9";
qatAccessCode.returnKeyLabel = ReturnKeyLabel.GO;
qatAccessCode.stage = this.stage;
qatAccessCode.viewPort = new Rectangle(225, 765, 200, 35 );

1 个答案:

答案 0 :(得分:2)

你制作一个String变量。和stageText添加更改事件。发生事件时存储的stageText属性text。稍后使用String变量。

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.geom.Rectangle;
import flash.text.ReturnKeyLabel;
import flash.text.SoftKeyboardType;
import flash.text.StageText;
import flash.events.Event;

var str:String;
var stageText:StageText = new StageText();
stageText.softKeyboardType = SoftKeyboardType.NUMBER;
stageText.restrict = "0-9";
stageText.returnKeyLabel = ReturnKeyLabel.GO;

stageText.stage = this.stage;
stageText.viewPort = new Rectangle(10, 10, 300, 40 );
stageText.addEventListener(Event.CHANGE, onChange);
function onChange(e:Event):void
{
    str = stageText.text;

    trace(str);
}