5 Replies Latest reply on Apr 19, 2010 2:40 PM by Florincugir

    Html and flex

    Investigator99

      Hi,

      I have been looking at discussions on this forum regarding flex and html and would like to ask a question.

       

      Since html may contain a flex component, is there a way of communicating between a flex component and its html container?

       

      From what I understand, it is possible for Flex to call out to a javascript located on the parent html page. Or using the ExternalAPI.

      However is it possible for the html to call back or send a message to a flex component?

       

      The reason I ask this is that I am investigating using a flex tree on html page, that would sit alongside a html frame. This html panel part has a form that can create or delete data which would have to be reflected in the flex tree.

       

      Any suggestions on how to get over this problem would be great or even if it is possible to communicate from html to flex components.

       

      Thanks,

       

      /Pat

        • 1. Re: Html and flex
          BennyBeta Level 4

          Yes, the HTML/JavaScript of the browser can call the Flex application.  You need to register a callback with ExternalInterface.

           

          Ben Edwards

          • 2. Re: Html and flex
            BennyBeta Level 4

            The following documentation has more information:

            http://www.flexafterdark.com/docs/Flex-JavaScript

             

             

            Calling ActionScript from JavaScript again requires use of the ExternalInterface class. First we must use the addCallback() function to expose the ActionScript function we want to call to the container.

             

               public function init():void
               {
                  // expose an ActionScript function to the container
                  ExternalInterface.addCallback( "doSomethingInActionScript", doSomethingInActionScript );
               }
              
               // function now callable from JavaScript
               public function doSomethingInActionScript( arg1:String, arg2:Number ):String
               {
                  return "result";
               }

             

            The below JavaScript code can be used to call the exposed ActionScript function:

             

               // get the Flex application (Flash object)
               var isIE = navigator.appName.indexOf("Microsoft") != -1;
               var flashName = "flashObjectName";
               var flashObject = (isIE) ? parent.Main.window[flashName] : document[flashName];
              
               if( flashObject )
               {
                  // call the Flex application (Flash object)
                  flashObject.doSomethingInActionScript( "arg1", 2 );
               }

             

             

            I hope that helps...

             

            Ben Edwards

            • 3. Re: Html and flex
              Investigator99 Level 1

              Thanks for that Ben.

               

              Will give it a shot.

               

              /Pat

              • 4. Re: Html and flex
                BennyBeta Level 4

                Let me know if it works.


                (And if it does, please hook me up with some points. Thanks.)

                 

                Ben

                • 5. Re: Html and flex
                  Florincugir Level 1

                  Hi Ben,

                   

                  I found that site ("flexafterdark") before looking in forum, but I didn't understand... They (and you) say you have to expose the ActionScript function (using ExternalInterface class)... Okay, but I want to call a FLEX application (basically a .swf), not a function! And even worse, I want to call it using parameters...

                  I am sure is something here I don't understand... but what?

                   

                  Could you, please, be a little more descriptive than those guys from that site?   

                   

                  Any help would be much appreciated!

                   

                   

                  Florin