【问题标题】:Get the value of multiple input texts with Actionscript 3使用 Actionscript 3 获取多个输入文本的值
【发布时间】:2014-07-13 23:22:27
【问题描述】:

我正在尝试创建一个 ActionScript 应用程序来计算采矿公司可以从河流中提取的沙子的体积。所以我进入了舞台,比如 4 个输入文本,分别命名为“WidthOne”、“WidthTwo”、“WidthThree”和“WidthFour”以及其他 4 个输入,“HeightOne”...“Height Four”。数学运算类似于 "WidthOne × HeightOne" ... "WidthFour × HeightFour",结果转到名为 "ResultOne" ... "ResultFour" 的动态字段。

有什么方法可以使用循环来获取这些字段的值,这样我就不需要手动完成所有操作,因为我需要在舞台中创建其他输入文本?我在 HTML 和 Javascript 中得到了一个工作,基本上它是这样的:

for(i=0;i<=3;i ++) {
    var WidthInputID = ['WidthOne','WidthTwo','WidthThree','WidthFour'];
    var HeightInputID = ['HeightOne','HeightTwo','HeightThree','HeightFour'];
    var ResultsInputID = ['ResultOne','ResultTwo','ResultThree','ResultFour'];

    var Width = document.getElementById(WidthInputID[i]).value;
    var Height = document.getElementById(HeightInputID[i]).value;
    var Result = document.getElementById(ResultsInputID[i]).value = Width*Height;
}

不知道是不是我说清楚了,因为我的英语不好,所以如果我不清楚,我很抱歉。

【问题讨论】:

    标签: javascript actionscript-3 flash loops input


    【解决方案1】:
    var widthInputID:Array = ['WidthOne','WidthTwo','WidthThree','WidthFour'];
    var heightInputID:Array = ['HeightOne','HeightTwo','HeightThree','HeightFour'];
    var resultsInputID:Array = ['ResultOne','ResultTwo','ResultThree','ResultFour'];
    
    for(i = 0; i <= 3; i++) {
    
        var width:Number = Number(this[widthInputID[i]].text);
        var height:Number = Number(this[heightInputID[i]].text);
        var result:Number = width*height;
        this[resultsInputID[i]].text = result;
    }
    

    【讨论】:

      【解决方案2】:

      您可以在 AS3 中遵循相同的策略。主要区别在于:

      1. 要访问舞台上的元素,您可以使用 document.getElementById("elementId")

        this["instanceName"]
        
      2. 文本字段内容的属性名称不是。该属性称为 text

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-15
        相关资源
        最近更新 更多