removeChild for external XML?

Hello -

I’m loading content into my .fla from an external XML file using URLLoader. Once the XML has loaded, I’m looping through the XML to create an XMLList for certain elements. I’m then creating a text field to contain those nodes. Each node gets its own text field so that I can easily create text links. Here’s my code (with non-pertinent lines removed):

//declare variables
var xml:XML;

//load XML file
var xmlLoader:URLLoader = new URLLoader();
var [url:URLRequest](http://www.kirupa.com/forum/URLRequest) = new URLRequest("xml/qchatTS3.xml");
xmlLoader.load(url);
xmlLoader.addEventListener(Event.COMPLETE, onXmlLoad);

//function to run once XML file loads;
function onXmlLoad(e:Event):void
{
 trace("xml loaded");
 //declare variables for on xml load function
 xml = new XML(xmlLoader.data);
 var verticalElements:XMLList = xml.verticals.vertical;
 var vertLen:int = verticalElements.length();

// loop
 for (var i:int = 0; i < vertLen; i++)
 {

//declare variables
  var verticalElement:XML = verticalElements*;
  var verticalIssueName:String = verticalElement.issuename;

//add intro issue text
  var introIssueTxt:TextField = new TextField();
  introIssueTxt.htmlText = verticalIssueName.toString();
  introIssueTxt.width = 260;
  introIssueTxt.height = 18;
  introIssueTxt.x = 507;
  introIssueTxt.y = 440 + i * 18;
  addChild(introIssueTxt);
  introIssueTxt.addEventListener(TextEvent.LINK, onIssueTextLink);
}
}

That’s all working fine.

The problem comes in when I navigate to a different section (frame) of my main timeline. I need to remove all of the intoIssueTxt text fields so I can display other text. I tried this code on the new frame:

removeChild(introIssueTxt);

but I got an error saying there’s an undeclared property. I think that’s because the original addChild is within a function so it’s not available?

I then tried moving the variable declaration [var introIssueTxt:TextField = new TextField();] out of the function and to the top of the code, but then I only got one text field with the last XML node – no loop.

Surely there’s got to be a way to remove all of the introIssueTxt text fields when I enter a new frame. Can anyone help?

Thanks!

Miriam