views:

52

answers:

3

Hi,

Is there any way to call from javascript to actionscript, not using JSON object.

thanks, Ravi

+4  A: 

ExternalInterface could be your friend :

http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html

or

http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_5.html

(I'm not sure the second link will work, though ... )

phtrivier
So from actionscript to javscript and vice versa, using ExternalInterface only. am i correct?
Ravi K Chowdary
Yes, you can either call a function declared in JS from AS, or register an AS function so that it can be called by JS.
phtrivier
By the way, ExternalInterface communicates using XML-encoded objects, not JSON. The encoding/decoding is done behind the scenes, transparent to your use, but the calls could take a long time if it has to encode a complex object in XML.
Cameron
+2  A: 

You can call a function inside your Flash with the following Javascript:

 <script>
 function callToFlash(param)
 {
      var fl = document.getElementById('idOfFlashObject');
      if(fl != null)
      {
          fl.functionInFlash(param);
      }
 }
</script>

More about this can be found at the Adobe Knowledge Base: http://kb2.adobe.com/cps/156/tn_15683.html

Pbirkoff
You have to register the function (using ExternalInterface.addCallback) in Flash first before it can be called from JavaScript.
Cameron
A: 

You might want to consider using the Flex-Ajax Bridge.

Read: About the Flex Ajax Bridge

Enjoy!

Bryan Clover