Writecoder
Writecoder

Reputation: 613

Flex ExternalInterface callback

Flex:

public function callFromJavaScript():String
{
       test.label='dfdsfsdf';
       return "1";
}
public function init():void {
       ExternalInterface.addCallback("sendToFlash", callFromJavaScript);
}

HTML

<object classid='clsid:x-x-x-x-x' height='200px' width='300px'>
        <param name="allowScriptAccess" value="always" />
        <param name='src' value='${swf}.swf'/>
        <embed  name='mySwf' id='qwe' src='${swf}.swf' height='200px' width='300px'/>
</object>

I know there are multiple (JavaScript) methods like: document.getElementById('FlexAppId').setName(name);

However:

  1. I have no clue which one are crossbrowser compatible (cant install IE to test out)
  2. I have tried multiple but I can't get them to work(in any browser), I'm probably using the wrong id, I've been trial & erroring for a couple of hours but I don't have anything working. (I heard there was a problem with ExternalInterface.addCallback on a local file system?, should I upload the swf? < is the flex code right& problem = JavaScript/html side?)

Upvotes: 0

Views: 1226

Answers (1)

Jim Jose
Jim Jose

Reputation: 1319

ExternalInterface functions are know to have issues across browsers and operating systems. Some of the recommendations are,

  1. User swfobject or any other standard library to embed your swf. (swfobject)
  2. Use 'allowscriptaccess=always'
  3. Give proper id and name to the embed tag
  4. id and name attribute should be always same.
  5. If your swf file is coming from a different domain than the html page, use Security.AllowDomain('domain-of-html-page.com')

Upvotes: 4

Related Questions