Reputation: 4934
I'm having trouble calling a function through the use of ExternalInterface.
First off, here's the HTML/JS side:
<p align="right">
<object type="application/x-shockwave-flash" data="camera.swf"
width="200" height="200" align="right" id="camSWF">
<param name="movie" value="camera.swf" align="right" />
<param name="allowScriptAccess" value="always" />
</object></p>
<script type="text/javascript">
var flashObj = document.getElementById('camSWF');
document.onmousemove = setMouseXY;
function setMouseXY(e) {
var x = e.pageX;
var y = e.pageY;
flashObj.rotateCam(x, y, $(document).width(), $(document).height());
}
</script>
And secondly, here is the ActionScript 2 code:
ExternalInterface.addCallback('setMouseXY', null, rotateCam);
function rotateCam(mouseX, mouseY, docWidth, docHeight)
{
// DO STUFF
}
As far as I can see, everything should work, but obviously I'm missing something.
Whenever the mouse event fires on the HTML page, I get this error in Firebug:
flashObj.rotateCam is not a function:
flashObj.rotateCam(x, y, $(document).width(), $(document).height());
I'm quite stuck. Perhaps it's some security thing?
Upvotes: 0
Views: 2295
Reputation: 25135
ExternalInterface.addCallback('setMouseXY', null, rotateCam);
This statement adds "rotateCam" as the callback function for "setMouseXY". So "setMouseXY" is the function that has to be called from javascript.
function setMouseXY(e) {
var x = e.pageX;
var y = e.pageY;
flashObj.setMouseXY(x, y, $(document).width(), $(document).height());
}
Upvotes: 2