Skip to main content
Participating Frequently
December 9, 2009
Question

What is wrong with this code for filling array with xml?

  • December 9, 2009
  • 2 replies
  • 343 views

I get the following error message:

TypeError: Error #2007: Parameter text must be non-null.

      at flash.text::TextField/set text()

      at quoteRotator_fla::MainTimeline/rototeQuote()

      at flash.utils::Timer/_timerDispatch()

      at flash.utils::Timer/tick()

over and over.

HERE IS THE CODE BELOW.

var quote:Array = new Array();
var author:Array = new Array();
var totalQuotes:Number;

var rotateTimer:Timer = new Timer(2000, 100); //rotates the quote every 2 seconds for 100 times
rotateTimer.addEventListener("timer", rotateQuote);//add a listener to the timer
rotateTimer.start(); // start the timer

function init():void {
    var quotesXML:XML = new XML();
    quotesXML.ignoreWhitespace = true;
    var XMLURL:URLRequest = new URLRequest("quotes1.xml");
    var myLoader:URLLoader = new URLLoader(XMLURL);
    myLoader.addEventListener("complete", xmlLoaded);
    function xmlLoaded(event:Event):void {
        quotesXML = XML(myLoader.data);
        totalQuotes = quotesXML.quote.length();
        for (var i:int = 0; i < quotesXML.quote.length(); i++) {
            quote = quotesXML.quote.text;
            author = quotesXML.quote.author;
        }
    }
}

function rotateQuote(evt:TimerEvent) {
    var randomness:Number = randomNumber(0, totalQuotes);
    quoteMC.quote_txt.text = quote[randomness];
    authMC.author_txt.text = author[randomness];
}

function randomNumber(low:Number, high:Number):Number {
    var low:Number = low;
    var high:Number = high;
    return Math.round(Math.random() * high - low) + low;
}
   
init();

This topic has been closed for replies.

2 replies

December 9, 2009

If you have 10 quotes, then you set totalQuotes to 10 - but the array goes from 0 - 9... you need to set totalQuotes to length - 1, not length.

kglad
Community Expert
Community Expert
December 9, 2009

what's your xml look like?