开发者

How to pass data via event from swf1 to swf2 where former is loaded in later

I have a swf(Swf1)that dispatches a CustomEvent

Swf1 : dispatchEvent( new CustomEvent("eventName", obj)) //Custom event is written in Swf1 that allows to attach data on dispatch. // do tell if there is anyother way to do this using inbuilt AS3 APIs.

Now Swf2: 开发者_StackOverflow社区(loads Swf1) added listener function onswf1loadComplete(e:Event){ _movie = MovieClip(e.target.content); _movie.addEventListener("eventName", callrequiredFunction); // how to get the obj here? }

(except that I need to define CustomEvent in Swf2 too)


You could externalize the loading of the SWfs to another class which would handle the communication between the two swfs...

 private var swf1:MovieClip; 
 private var swf2:MovieClip; 

 private function loadSWF(url:String):void
 {
     //loading swf code
 }

 private function init():void
 {
    loadSWF( swf2URL );
  }

 private function completeHandler (event:Event ):void
 {
     switch( event.currentTarget.name)
     {
         case 'swf1':
           swf1 = new Whatever();
           //swf1.addEventistener( CustomEvent.SWF1 , swfEventListener );
           swf1.addEventistener( Event.COMPLETE , completeEventListener );               
           swf1.init();
           break;

        case 'swf2':
           loadSWF( swf1URL );
           break;
     }           
 }

 private function completeEventListener( event: Event):void
 {
      //where result is a getter on the Whatever class
      var object:Object = swf1.result;
 }

 private function swfEventListener( event: CustomEvent):void
 {
      if( event.type == CustomEvent.SWF1 )
          var object:Object = event.object;
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜