3

I am trying to figure how to pass string value(url) from html form to embedded flex object. the only method i found so far is "addCallback" method described in http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_5.html In the example i used flex function "myFunc(s:String)" is registered with "ExternalInterface" and called later from javascript

--->mySwf.mxml:

<?xml version="1.0"?>
<!-- wrapper/AddCallbackExample.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
  <mx:Script>
     import flash.external.*;
      import mx.controls.Alert;
     public function initApp():void {
        ExternalInterface.addCallback("myFlexFunction",myFunc);
     }  
     public function myFunc(s:String):void {

         Alert.show(s, 'Alert Box', mx.controls.Alert.OK);
     }

  </mx:Script>
  <mx:Button id="myButton" 
        label="FLEX BUTTON" 
        click="Alert.show('FLEX LOADED!', 'Alert Box', mx.controls.Alert.OK);"/>
  <mx:Label id="l1"/>

</mx:Application>

external.html

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<SCRIPT LANGUAGE="JavaScript">
    function callApp() {

        mySwf.myFlexFunction("show me something");
    }
</SCRIPT>


<form id="f1">
    <button onClick="callApp()">HTML BUTTON</button>
</form>

<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
WIDTH="850"
HEIGHT="610"
CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">
<EMBED SRC="mySwf.swf"
WIDTH="850"
HEIGHT="610"
PLAY="true" 
LOOP="true"
QUALITY="high" 
scale="noborder"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> 
</EMBED>
</OBJECT>
</html>

The method doesn't seem to be working at all. If I push Flex button - i can see Flex popup dialog. When I push HTML button, calling myFunc in Flex via ExternalInterface - nothing
happens... Any pointers to errors in my code? Thank you,

2
  • 1
    You should always format your code as code, especially because XML tags will not be shown otherwise. Use the {} button or indent 4 spaces. I did it for you this time. Commented Feb 19, 2011 at 14:39
  • which browser are you testing it on? Commented Feb 19, 2011 at 14:47

1 Answer 1

1

Try this in case you aren't using the right browser:

<SCRIPT LANGUAGE="JavaScript">
    // This function returns the appropriate reference, 
    // depending on the browser.
    function getFlexApp(appName)
    {
      if (navigator.appName.indexOf ("Microsoft") !=-1)
      {
        return window[appName];
      } 
      else 
      {
        return document[appName];
      }
    }

    function callApp() {
        getFlexApp('mySwf').myFunc("show me something");
    }

</SCRIPT>

also you did not give an id to your object which is how the DOM identifies

<OBJECT id='mySwf' CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">

try this:

ExternalInterface.addCallback("myFunc",myFunc);
Sign up to request clarification or add additional context in comments.

12 Comments

please take a look at the answer. you did not attach id='mySwf' on the Object
Tried everything you suggested - no difference so far.
Can you suggest other methods to do it ( pass arg from html to flex)?
Try see if you can setup this tutorial switchonthecode.com/tutorials/…
from error console: Error: getFlexApp("mySwf").myFlexFunction is not a function
|

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.