0

In the following I am trying call action script function from js function. What am I doing wrong here? Should we include action script filename swf file here:

 <html>
 <body>
  <input type="button" value="click" onclick="ExternalInterface.addCallback('addblock', addblock);" />
 </body>
 </html>     

AS code:

 <?xml version="1.0" encoding="utf-8"?>
 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    
<mx:Script>
    <![CDATA[
        
        
        import mx.controls.Alert;
        import mx.controls.Button;
        
        
  
        public static var cam:Camera =  Camera.getCamera();
        public static var video:Video = new Video(10, 20);
        public function addblock():Void
        {
            Alert.show("Got 1");
    
        }
            
    
        ]]>
    
</mx:Script>



  </mx:Application>

1 Answer 1

3

HTML example using the swfobject library:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="swfobject.js"></script>
  </head>
  <body>
    <div id="test"></div>
    <a href="#" onclick="document.getElementById('test').addBlock();">Call addBlock</a>
    <script type="text/javascript">
      swfobject.embedSWF('test.swf', 'test', '300', '300', '9.0.124', 'expressInstall.swf');
    </script>
  </body>
</html>

Flex application example:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="300" height="300" creationComplete="init()">
  <mx:Script>
  <![CDATA[
    import mx.controls.Alert;

    private function init():void
    {
      ExternalInterface.addCallback('addBlock', addBlock);
    }

    private function addBlock():void
    {
      Alert.show("addBlock called");
    }
  ]]>
  </mx:Script>
</mx:Application>
Sign up to request clarification or add additional context in comments.

5 Comments

I modified the answer to include concrete examples.
Thank u very much ,Would get back to you
i get an error saying document.getElementById('test').addBlock(); is not a function??
Is it with that exact example? Asking because it works for me.
My mistake got it working.Thanks +1 for the help and the answer.Please do post any useful links if u find so any..Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.