Hi,
These days I’m learning the different usages of EventDispatcher class and understanding it’s working.
Any ways here is my another confusion :
Let me write the code first
[AS]
//this is menu class which builds a menu based on xml file
import mx.events.EventDispatcher;
class menu extends MovieClip
{
private var thisTarget:MovieClip;
public var addEventListener:Function;
public function menu ()
{
thisTarget = this;
}
public function init (xmlFile)
{
var menu_xml = new XML ();
EventDispatcher.initialize (this);
//i can have n number of listeners listening to the xml load event
//so that i can take appropriate actions on different components
var xmlListener = new Object ();
xmlListener.xmlLoaded = function (evtObj)
{
//this outputs undefined
trace (evtObj.target);
};
this.addEventListener (“xmlLoaded”, xmlListener);
menu_xml.onLoad = function (succ)
{
if (succ)
{
//this outputs undefined.
trace(thisTarget);
thisTarget.dispatchEvent ({type:“xmlLoaded”, target:thisTarget});
}
};
menu_xml.load (xmlFile);
}
}
[/AS]
Considering the above code if for example I want to broadcast the event of onLoad of xml to different listeners objects with the scope of movieClip in which the xml object is declared, so that later mcs from the library can be attached dynamically.
However this approach does not seem to work.
Hope i have made my doubt clear.
Answers please.