Reputation: 114
This code does not work. (Passing variable from AS3 to Javascript)
AS3 (declare variable and pass to Javascript)
var newHeight:Number = new Nubmer();
newHeight = 2;
goHeight();
function goHeight():void{
if (ExternalInterface.available){
ExternalInterface.call("funYa1()", newHeight);
}
}
In the HTML docment:
<script type="text/javascript">
function funYa1(nH) {
alert("newHeight " + nH);
}
</script>
The alert says nH is undefined. Any ideas?
Upvotes: 2
Views: 77
Reputation: 1153
The alert says nH
is undefined because you have braces in the call. In this case argument is not passed. Substitute the row
ExternalInterface.call("funYa1()", newHeight);
with
ExternalInterface.call("funYa1", newHeight);
and argument should be delivered to Javascript.
Upvotes: 2
Reputation: 4530
You have a typo in the first line
var newHeight:Number = new Nubmer();
should be
var newHeight:Number = new Number();
Are you using swfObject to embed swf? If yes, try adding:
<param name="allowscriptaccess" value="always">
Also you could try passing a hard-coded string instead of newHeight, to see if it is a problem with the variable:
ExternalInterface.call("funYa1()", "test");
Here is a nice article about as3 and javascript communication:
http://circlecube.com/2010/12/actionscript-as3-javascript-call-flash-to-and-from-javascript/
Upvotes: 3