在 AS3 中拆分值并将其放入文本框中

发布于 2024-10-27 10:25:55 字数 696 浏览 1 评论 0原文

我在一个文本框中输入一组 4 个值,然后使用以下代码在其他 4 个小文本框中以拆分方式显示它:

array.push(Number(t1.text));
array.push(Number(t2.text));
array.push(Number(t3.text));
array.push(Number(t4.text));

b2.addEventListener(MouseEvent.CLICK, act2);
//ACTION OF THE THE FIRST BUTTON CLICK
function act1(event:MouseEvent):Array 
{
    var input:String = tt.text;
    array = input.split(" ");
    t1.text=array[0];
    t2.text=array[1];
    t3.text=array[2];
    t4.text=array[3];
}

但现在我需要知道如何对输入的任何动态值执行相同的操作。

假设我有一个文本框 tt1 和一个按钮 b1。当我输入任何值(比如 6)时,会创建这个数量的文本框(6 个名为 t0,t1....t5 的新文本框),

我有另一个文本框 tt2 和按钮 b2。当我在其中输入一组值(例如 10,66,33,45,2,4)时,我需要将这些值显示在这些文本框中 t0,t1,t2..

这可能吗?

I enter a set of 4 values in one text box and i display it in a splitted way in 4 other small text boxes using this code:

array.push(Number(t1.text));
array.push(Number(t2.text));
array.push(Number(t3.text));
array.push(Number(t4.text));

b2.addEventListener(MouseEvent.CLICK, act2);
//ACTION OF THE THE FIRST BUTTON CLICK
function act1(event:MouseEvent):Array 
{
    var input:String = tt.text;
    array = input.split(" ");
    t1.text=array[0];
    t2.text=array[1];
    t3.text=array[2];
    t4.text=array[3];
}

But now I need to know how to do the same thing for any dynamic value that is entered.

Say I have a text box tt1 and a button b1. When I enter any value (say 6) this number of text boxes are created (6 new text boxes with names t0,t1....t5)

I have another text box tt2 and a button b2. When i enter a set of values in it (say 10,66,33,45,2,4) I need these values to get displayed in those text boxes t0,t1,t2..

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以歌曲疗慰 2024-11-03 10:25:55

此代码片段将创建您的文本字段

// this will hold our new textfields
var textfields:Array = new Array();

function handleCreateFields(e:Event):void {
    // assuming your textfield for the number of fields to be created 
    // is named tfNumfields
    var count:int = parseInt(tfNumfields.text);

    for( var i:int = 0; i < count; i++){
        var tf:TextField = new TextField();
        tf.x = 100;
        tf.y = 100 + i * 30;
        addChild(tf);
    }
}

此代码片段将把文本字段的内容拆分为多个文本字段

function handleCreateFields(e:Event):void {
    // assuming your textfield for the values is named tfValues
    var values:Array = tfValues.split(" ");

    for( var i:int = 0; i < textfields.length && i < values.length; i++){
        textfields[i].text = values[i];
    }
}

This snippet will create your textfields

// this will hold our new textfields
var textfields:Array = new Array();

function handleCreateFields(e:Event):void {
    // assuming your textfield for the number of fields to be created 
    // is named tfNumfields
    var count:int = parseInt(tfNumfields.text);

    for( var i:int = 0; i < count; i++){
        var tf:TextField = new TextField();
        tf.x = 100;
        tf.y = 100 + i * 30;
        addChild(tf);
    }
}

This snippet will split the contents of your textfield into multiple textfields

function handleCreateFields(e:Event):void {
    // assuming your textfield for the values is named tfValues
    var values:Array = tfValues.split(" ");

    for( var i:int = 0; i < textfields.length && i < values.length; i++){
        textfields[i].text = values[i];
    }
}
空城缀染半城烟沙 2024-11-03 10:25:55

有可能:

b1.addEventListener(MouseEvent.CLICK, createTextFields);
b2.addEventListener(MouseEvent.CLICK, showValues);

var textFields:Array = [];

function createTextFields(event:MouseEvent):void
{
    var quantity:uint = uint(tt1.text);
    for (var i:int = 0; i < quantity; i++)
        textFields.push(createTextField(i));
}
function showValues(event:MouseEvent):void
{
    const SEPARATOR:String = " ";  // or "," or whatsoever
    var values:Array = tt2.text.split(SEPARATOR);
    for (var i:int = 0; i < values.length; i++)
        textFields[i].text = values[i];
}
function createTextField(i:int):TextField
{
    // create the text field and add it to the stage if you want
}

我建议您检查输入的值的数量是否是您刚刚创建的文本字段的数量。

It is possible:

b1.addEventListener(MouseEvent.CLICK, createTextFields);
b2.addEventListener(MouseEvent.CLICK, showValues);

var textFields:Array = [];

function createTextFields(event:MouseEvent):void
{
    var quantity:uint = uint(tt1.text);
    for (var i:int = 0; i < quantity; i++)
        textFields.push(createTextField(i));
}
function showValues(event:MouseEvent):void
{
    const SEPARATOR:String = " ";  // or "," or whatsoever
    var values:Array = tt2.text.split(SEPARATOR);
    for (var i:int = 0; i < values.length; i++)
        textFields[i].text = values[i];
}
function createTextField(i:int):TextField
{
    // create the text field and add it to the stage if you want
}

I recommend you to check if the number of values entered is the number of text fields you've just created.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文