PDA

View Full Version : XML loader event bubble


piep
11-01-2007, 05:33 PM
Hi,

I have 3 classes:

1. grid.as (defines a custom/enhanced datagrid)
2. getdata.as (loads XML content using URLLoader)
3. document class (creates datagrid from custom datagrid class and tries to feed the data from the getdata class)

problem is that the grid is instatiated immediately, and it takes some time to load the XML.

this doesn't work:

public class getdata extends MovieClip
{
public function getdata() {}
public function getXML():XML
{
var externalXML:XML;
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("facturen.xml");
loader.load(request);
loader.addEventListener(Event.COMPLETE, onComplete);
addEventListener(Event.COMPLETE, onComplete);
return externalXML;
}
private function onComplete(event:Event):XML
{
var xmldoc:XML;
var loader:URLLoader = event.target as URLLoader;
if (loader != null)
{
xmldoc = new XML(loader.data);
trace(xmldoc.toString());
}
else
{
trace("getdata.as :: Error loading XML file");
}
return xmldoc;
}
}


Question: how can I feed the XMLdata to the grid at the very moment that the Complete event happen? Can I bubble the event from my 'getdata' class to the 'grid' or to the DC? :confused:

thanks

piep
11-05-2007, 09:01 AM
Is it possible to generate custom events that can be picked up bu the parent object? And is there somewhere an event bubbling tutorial?

FrodoBaggins
11-05-2007, 09:42 AM
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html shows an example of event bubbling, http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/EventDispatcher.html show an example of how to create custom events.