1
votes

I'm calling a JS function with ExternalInterface.call and trying to get a return value inside Flash. When I trace out the op variable I get 0 instead of 500. Is there something wrong with my embed code?

Embed code:

<embed src="/sites/default/files/flash/flashgame/Preload.swf" width="975" height="572" align="middle" FlashVars="entry=login" quality="high" bgcolor="#ffffff" name="slider" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />

JS:

function get_current_points(){
    // Hardcoded return value for testing
    return 500;
}

Actionscript:

var op:Number = ExternalInterface.call("get_current_points") as Number;
5
Before anything - why are you, in the example, calling "get_current_points" when the function name is "leansy_get_current_points"? - Robert Bak
I edited it. That was a mistake in my question only, the functons matched in my code. - knuckfubuck

5 Answers

1
votes

@knuckfubuck, I think your are not using the correct function name as pointed out by RobertBak. Otherwise the code is perfectly fine when I run it on my m/c.

@OXMO456, 'as Number' has nothing to do with this problem. In this case both 'Number(Ext....)' and ' Ext.. as Number' are working fine.

Hope it helps, Ashine.

===============================================================================

@khuckbuck in response to your comment, I am sure the function is not getting visible in Flex. Try using 'if (ExternalInterface.available)' inside flex to check if the interface is accessible to flex. This will help us pin pointing the problem.

1
votes

Also, I don't think you can get a return value from an External Interface call. I think you need to set up a callback function. ActionScript calls JavaScript, then JS calls AS back with a separate function.

If you had to wait for the return value for each cross-script call, it would probably slow your movie to a crawl.

0
votes

I think you get a 0 cause you're using: as Number.

Use Number(ExternalInterface.call("get_current_points")) instead.

0
votes

is it just in this example, or can it be that you have a mismatch in function names?

because the value should be NaN instead of 0, if you don't get a valid return value.

otherwise your code seems to be correct.

0
votes

Get return value in Flash is risky. It doesn't work as expected on all browser. Actually I'm reworking my code coz Internet Explorer refuse to send back returned values. I suggest to use Justin Putney's advice.

Regards