【问题标题】:AS3 modification to read text from array not from xmlAS3修改从数组而不是从xml读取文本
【发布时间】:2015-03-04 15:26:57
【问题描述】:

请帮我修改 AS3 代码以从数组而不是 xml 中读取文本。

原代码:

function readTheText() {
// Zeroing the TEXT
// ------------------------------------------
DisplayHolder.MultiLetters_MC.TheText = "";
// clear the previous interval
clearInterval(PhraseChange);
// ------------------------------------------
// Reading the text from the XML
// ------------------------------------------
for (i=0; i < NumOfLines; i++) {
    this["textLine"+i] = myXml.firstChild.childNodes[LinesCount].childNodes[i].firstChild.nodeValue;
    if (this["textLine"+i] == undefined){
        this["textLine"+i] = " ";
    }
    padLength = NumOfLettersInLine - this["textLine"+i].length;
    // Add padding if necessary
    if (padLength > 0){
        for (p=0; p < padLength; p++) {
            this["textLine"+i] += " ";
        }
    } else {
        // Subtract letters if necessary
        var theString:String = this["textLine"+i];
        var theSubString:String = theString.substring(0,NumOfLettersInLine);
        this["textLine"+i] = theSubString;
    }
    // Our final text
    DisplayHolder.MultiLetters_MC.TheText += this["textLine"+i];
}...

将从 xml 读取替换为:

    var group1:Array = ['DRIFT', 'FRESH&TONIC', 'SHIT ON GRASS', 'DOWNTOWN', 'AGED NEGRONI', 'FIREBALL', 'B5200', 'BLACK JACK', 'HOT WORM'];
var texts:Array = [];

最好的问候

【问题讨论】:

  • 我不明白你的问题是什么,但如果你想读取数组元素,你只需要使用for 循环。看看来自 help.adobe.com 的 working with arrays

标签: xml actionscript-3 flash


【解决方案1】:
  1. NumOfLines 替换为group1.length
  2. myXml.firstChild.childNodes[LinesCount].childNodes[i].firstChild.nodeValue; 替换为group1[i];

【讨论】:

    猜你喜欢
    • 2018-10-03
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    相关资源
    最近更新 更多