views:

352

answers:

3

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;
A: 

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.

greetz

back2dos

back2dos
If I take off the "as Number" casting I get NaN, with it I get 0.
knuckfubuck
A: 

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

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

OXMO456
+1  A: 

@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.

Ashine
you're right ! :|
OXMO456
I edited my question. The function name mismatch was a mistake in my question only. In the code they match and the return var does not work.
knuckfubuck
Hmm. In this case 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.
Ashine