0

How can I modify AS3 code to read text from array not from xml.

original code:

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];
}...

replace reading from xml with:

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

1
  • I don't understand what's your problem, but if you want to read array elements you have just to use a for loop. Take a look on working with arrays from help.adobe.com. Commented Mar 4, 2015 at 15:33

1 Answer 1

1
  1. Replace NumOfLines with group1.length.
  2. Replace myXml.firstChild.childNodes[LinesCount].childNodes[i].firstChild.nodeValue; with group1[i];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.