Problem with addChild in CS3

I’ve just started using AS3 after knowing a tiny bit of AS2, so sorry if this is a noobish question, anyway…

Basically when using a foreach loop on an XML document (from the kirupa example) I cannot use addChild when duplicating a movieclip (from another kirupa example).

I tried combining the XML book example with the BlueCircle duplication example because I want to achieve a similar thing with a box appearing, in this case, for each book and inside it the details of the book would put into a dynamic text box.

I probably haven’t explained it very well, but heres a snippet of the code I’m using and below that the error given. I’m guessing it’s because the XML uses addChild as well, so the two get confused, but I have no idea how to fix the problem.


var bookChildren:XMLList = bookInput.Book.children();
 
for each (var bookInfo:XML in bookChildren) {

function Main() {

var newCircle:BlueCircle = new BlueCircle();
newCircle.x = 50;
newCircle.y = 75;

this.addChild(newCircle);

}
Main();



trace(bookInfo);

}

}


XML Output
------------------------
TypeError: Error #1006: addChild is not a function.
    at MethodInfo-5()
    at test2_fla::MainTimeline/ParseStatus()
    at test2_fla::MainTimeline/LoadXML()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/flash.net:URLLoader::onComplete()

If anyone knows how to solve the problem I would be grateful.

Thanks in advance,

Michael