如何通过事件将数据从 swf1 传递到 swf2(前者稍后加载)

发布于 2024-10-04 23:50:04 字数 385 浏览 4 评论 0原文

我有一个 swf(Swf1) 调度 CustomEvent

Swf1 : dispatchEvent( new CustomEvent("eventName", obj)) //自定义事件是用 Swf1 编写的,允许在调度时附加数据。 // 请告知是否有其他方法可以使用内置 AS3 API 来执行此操作。

现在Swf2:(加载Swf1) 添加了监听器 函数 onswf1loadComplete(e:Event){ _movie = MovieClip(e.target.content); _movie.addEventListener("事件名称", callrequiredFunction); // 如何获取这里的 obj? (除了

我也需要在 Swf2 中定义 CustomEvent)

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: (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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情愿 2024-10-11 23:50:04

您可以将 SWf 的加载外部化到另一个类,该类将处理两个 swf 之间的通信...

 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;
 }

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;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文