7 Replies Latest reply on Aug 14, 2008 8:35 AM by Newsgroup_User

    Calling methods in embedded SWF

    justria Level 1
      In an AIR application, I embed other Flex apps [SWFs] as part of the main AIR app.

      Embedding works like a charm, but I need to interact between the master and the (generic) slaves [the embedded SWFs].

      As far as I understand the docs, master and client can't exchange methods. Do I understand the docs correctly?

      If master and client can't exchange methods, I may provide two bindable properties in the client:

      quote:

      [Bindable]
      public var inChannel:*;
      [Bindable]
      public var outChannel:*;



      In case the master wants the client to perform an action, I assign the client's inChannel, which in turn fires a handler inside the client. If the client finished its work, it in turn assigns a return value to outChannel. This then fires a handler in the master.

      Any ideas, if this strategy is OK? Or should I manage this situation in some other way?

      Thx,

      Stefan
        • 1. Re: Calling methods in embedded SWF
          augur_guan
          You typically embed a Flex application when you do not require the embedding application to interact with the embedded application. If the embedding application requires interactivity with the embedded application, you might consider implementing it as a custom component, rather than as a separate application.

          Alternatively, if you use the SWFLoader control to load the Flex application at run time, the embedding application can interact with the loaded application to access its properties and methods. For more information and examples, see Interacting with a loaded Flex application.
          • 2. Re: Calling methods in embedded SWF
            justria Level 1
            Thx! But that's basically where I am.

            I need to implement an AIR application, which might get enhanced through other SWFs, which provider further functionality. Think of the AIR app as a widget manager, which other other developers may provide new widgets for.

            The widget manager then downloads and embeds the widgets as SWFs.

            Thus, the widgets tend to be generic, but conform to a certain protocol, e.g. 'resize to new dimensions'.

            While the widgets are likely to conform to a class interface, I don't know much of them.

            I indeed use SWFLoader, but I fail to call method, I don't know beforehand.
            • 3. Calling methods in embedded SWF
              justria Level 1
              Here is how I load widgets:

              quote:

              var loaderContext: LoaderContext = new LoaderContext();
              loaderContext.allowLoadBytesCodeExecution = true;

              aLoader = new SWFLoader();
              aLoader.source = bytes;
              aLoader.loaderContext = loaderContext;

              ww = new CFlexletContainer();
              ww.inner = aLoader ;

              mainGrid. addChild( ww );



              Then, this fails:

              quote:

              aLoader.inChannel = 'Hello';
              • 4. Re: Calling methods in embedded SWF
                justria Level 1
                I then tried using SystemManager

                quote:

                loadedSM = SystemManager( aLoader.content );


                to assign a property:

                quote:

                loadedSM.application[ 'inChannel' ] = 'Hello';


                which fails, since array access evaluates to null.

                • 5. Re: Calling methods in embedded SWF
                  Level 7

                  "justria" <webforumsuser@macromedia.com> wrote in message
                  news:g81j07$hv4$1@forums.macromedia.com...
                  > Here is how I load widgets:
                  >
                  >
                  quote:

                  var loaderContext: LoaderContext = new LoaderContext();
                  > loaderContext.allowLoadBytesCodeExecution = true;
                  >
                  > aLoader = new SWFLoader();
                  > aLoader.source = bytes;
                  > aLoader.loaderContext = loaderContext;
                  >
                  > ww = new CFlexletContainer();
                  > ww.inner = aLoader ;
                  >
                  > mainGrid. addChild( ww );
                  >

                  >
                  > Then, this fails:
                  >
                  >
                  quote:

                  aLoader2.inChannel = 'Hello';


                  http://www.cflex.net/showFileDetails.cfm?ObjectID=690&Object=File&ChannelID=1


                  • 6. Re: Calling methods in embedded SWF
                    justria Level 1
                    Hm, wait, there might be some other problem. I'll come back later...
                    • 7. Re: Calling methods in embedded SWF
                      justria Level 1
                      Thx, solved! It works, as described by your post!

                      In fact, the CFlexletContainer is buggy.