第三方静态类实现子swf与父swf的通信
可以用第三方静态类来进行传递:
//EventDispatcherX.as
package {
? ? ? ? import flash.events.EventDispatcher;
? ? ? ? public class EventDispatcherX {
? ? ? ? ? ? ? ? public static??const dispatcher:EventDispatcher=new EventDispatcher;
? ? ? ? }
}
package?
{
? ?? ???import flash.display.Sprite;
? ?? ??
? ?? ???import flash.events.Event
? ?? ???public class LibClass extends Sprite
? ?? ???{
? ?? ?? ?? ?? ? public function LibClass()
? ?? ?? ?? ?? ? {
? ?? ?? ?? ?? ?? ?? ?? ?EventDispatcherX.dispatcher.dispatchEvent(new Event("go"));
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EventDispatcherX.dispatcher.addEventListener("return",getMainCall);
? ?? ?? ?? ?? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? private function getMainCall(e:Event):void{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? trace("get Main‘s Call!")
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ?? ???}
}
package?
{
? ?? ???import flash.display.Loader;
? ?? ???import flash.display.Sprite;
? ?? ???import flash.events.Event;
? ?? ???import flash.net.URLRequest;
? ?? ???
? ?? ???
? ?? ???public class Main extends Sprite
? ?? ???{
? ?? ?? ?? ?? ? public function Main()
? ?? ?? ?? ?? ? {
? ?? ?? ?? ?? ?? ?? ?? ?var myLoaderoader = new Loader();
? ?? ?? ?? ?? ?? ?? ?? ?myLoader.load(new URLRequest("LibClass.swf"))
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EventDispatcherX.dispatcher.addEventListener("go", testHandler)
? ?? ?? ?? ?? ?? ?? ?? ?addChild(myLoader)
? ?? ?? ?? ?? ?? ?? ?? ?myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, actionHandler);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ?? ?? ?? ?? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ?? ?? ?? ?? ? private function actionHandler(e:Event):void
? ?? ?? ?? ?? ? {
? ?? ?? ?? ?? ?? ?? ?? ?trace("action的侦听器: " + e);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EventDispatcherX.dispatcher.dispatchEvent(new Event("return"))
? ?? ?? ?? ?? ? }
? ?? ?? ?? ?? ? private function testHandler(e:Event)
? ?? ?? ?? ?? ? {
? ?? ?? ?? ?? ?? ?? ?? ?trace("ok i get it")
? ?? ?? ?? ?? ? }
? ?? ???}
}