Skip to main content
Inspiring
June 18, 2009
Question

I do not know why I have this error??

  • June 18, 2009
  • 2 replies
  • 794 views

Hi,

I had created a list that load content from XML file like this:

var MyURLRequest:URLRequest=new URLRequest("Content Files/MusicXML.xml");
var MyXMLLoader:URLLoader = new URLLoader();
var MusicXML:XML;
var MyXMLList:XMLList;
import fl.controls.List;
MyXMLLoader.addEventListener(Event.COMPLETE,OnLoad);
function OnLoad(event:Event):void {
MusicXML=new XML(event.target.data);
MyXMLList=MusicXML.Type;
for (var i=0; i<=MyXMLList.length()+1; i++) {
  SongList.addItem({data:i,label:MyXMLList.Song.@SongName});
}
}
MyXMLLoader.load(MyURLRequest);

It works just fine, but when I load this movie into my main movie the bolded line gives me this error:

TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/drawBackground()
at fl.controls::LabelButton/draw()
at fl.core::UIComponent/drawNow()
at fl.controls::List/drawList()
at fl.controls::List/draw()
at fl.core::UIComponent/callLaterDispatcher()

how can I solve this error??

Thanks a lot.

This topic has been closed for replies.

2 replies

Participating Frequently
June 19, 2009

How to write a for loop for an array

// Push something into an array

var arrSomeArray:Array = new Array();

arrSomeArray.push("1");

arrSomeArray.push("2");

// Calculate it's length beforehand

var ilength:uint = arrSomeArray.length;

// Loop through it

for (var iIndex:int = 0; iIndex < ilength; ++iIndex)

{

     // Do Something with arrSomeArray[iIndex]

}

Ned Murphy
Legend
June 18, 2009

The problem may be with exceeding the array length in the loop:   i<=MyXMLList.length()+1;

Under normal conditions the end of the loop should be at...  i < MyXMLList.length();

Inspiring
June 18, 2009

even if I do the loop to the length without adding 1 the problem still there!!

Ned Murphy
Legend
June 18, 2009

Did you also replace the <= with just <?  The way you had it, it was exceeding what would normally be the number of items by 2, so just removing the +1 would still have it too high.

The length of an array is 1 greater than the last index.  If you have an array with 10 items, the index of the last item is 9.  So to loop thru them you want to go from 0 to length-1