;

PDA

Click to See Complete Forum and Search --> : problem with ExternalInterface class


absolutezero342
08-05-2009, 12:55 PM
ok, here's my AS3 code:


if (ExternalInterface.available)
{
// Perform ExternalInterface method calls here.

var banner_width:Number = ExternalInterface.call("getWidth");
//var banner_width:Number = 500;
ExternalInterface.call("trace", banner_width);
}


and here's my Javascript:


function getWidth() {
var banner_width = 600;
return banner_width;
}

function trace(val) {

alert(val + ' = width');
}


this works in FF and outputs 600 like expected and it doesn't work in IE, instead it outputs 0??? why is this handled differently in different browsers?
thanks in advance!

joshstrike
08-05-2009, 01:47 PM
Make sure you have allowScriptAccess = 'always' or 'samedomain' , and allowNetworking = 'all' or 'internal' ...and make sure you have those set in BOTH the object and embed tags. It may be that IE is reading the object tag only and people sometimes neglect to add those tags there. See if that helps...

absolutezero342
08-05-2009, 02:15 PM
I have "allowScriptAccess" set to "always" in both the OBJECT and EMBED tags...I don't see the "allowNetworking" property but I don't think this is the issue...everything works EXCEPT in IE the return of the function "getWidth()" never returns the correct value...it's like returning a value to AS3 doesn't work properly in IE but it does work fine in FF???

I can pass params TO IE thru my AS3 code, so I know it's working in that respect, but when it comes to a return value for the function, it always bombs out! ideas? thx for the responses!

joshstrike
08-05-2009, 02:30 PM
I haven't encountered this problem, but I've also never used ExternalInterface to directly return a value like that. Does it work if you do it through a callback function? Try this:

Flash:

ExternalInterface.addCallback('gotWidth',this.gotW idth);
function gotWidth(w:*):void {
ExternalInterface.call('jsAlert',w);
}
ExternalInterface.call('jsGetWidth');


Javascript:

function jsGetWidth() {
document.getElementById('myMovie').gotWidth(banner _width);
}
function jsAlert(w) {
alert(w);
}

absolutezero342
08-05-2009, 04:24 PM
the examples seem to provide for a return result like that....the way you mentioned should work, but of course doesn't, even with tailoring...it's like it doesn't recognize my named Flash object within the HTML page. I have id and name set to "banner" and the documentation says to do it this way from Javascript:


...
var result = banner.gotWidth(someWidth);
...


of course it doesn't work....also, does the DOM get processed differently in different browsers?

cancerinform
08-05-2009, 07:04 PM
The answer to your problem may be here:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html
You may have to use a delay.
I don't have any Flash here currently, so I cannot check it myself.