Hi All,
I’ve been struggling getting JavaScript to Communicate back to my flash app.
Works fine in IE. But Firefox is making me lose my hair fast!
the framingSoftware SWF calls the addFrame JS function, the alert appears fine, but nothing is received back in flash…
Please can someone help me out!
I’m using SWFObject. AS3.
Thanks
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="../swfobject/swfobject.js"></script>
<script>
function addFrame(id, title) {
alert("FrameID: " + id);
alert(thisMovie("photoSWF"));
thisMovie("photoSWF").updateFrame("1");
}
function thisMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
</script>
</head>
<body>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="390" height="330" id="photoSWF" name="photoSWF">
<param name="movie" value="nopPicture.swf" /><param name="allowscriptaccess" value="always" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="nopPicture.swf" width="390" height="330"><param name="allowscriptaccess" value="always" />
<param name="photoSWF" value="nopPicture.swf" />
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
<br />
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="730" height="400" id="framingSWF">
<param name="movie" value="framingSoftware.swf" /><param name="allowscriptaccess" value="always" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="framingSoftware.swf" width="730" height="400"><param name="allowscriptaccess" value="always" />
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</body>
package com.nopPicture
{
import flash.display.Sprite;
import flash.display.LoaderInfo;
import com.alanfriend.framing.Painting
import flash.events.Event;
import flash.events.MouseEvent;
import flash.external.ExternalInterface
import flash.text.TextField
import flash.system.Capabilities
import com.thecoconutstudio.library.shapes.DrawRectangle
public class NopPicture extends Sprite
{
private var _painting:Painting;
private var output:TextField;
public function NopPicture()
{
stage.addEventListener(MouseEvent.MOUSE_UP, ini);
}
private function ini(e:MouseEvent):void
{
output = new TextField();
output.y = 25;
output.width = 450;
output.height = 325;
output.multiline = true;
output.wordWrap = true;
output.border = true;
output.text = "hello...
";
if (ExternalInterface.available) {
try {
output.appendText("ready for JS
");
ExternalInterface.addCallback("updateImage", onUpdateImage);
ExternalInterface.addCallback("updateFrame", onUpdateFrame);
ExternalInterface.addCallback("updateMount", onUpdateMount);
ExternalInterface.addCallback("updateGlaze", onUpdateGlaze);
} catch (error:SecurityError) {
output.appendText("A SecurityError occurred: " + error.message + "
");
} catch (error:Error) {
output.appendText("An Error occurred: " + error.message + "
");
}
} else {
output.appendText("External interface is not available for this container.");
}
addChild(output);
}
private function onPaintingReady(e:Event):void
{
}
private function onUpdateImage(value:String):void
{
output.appendText("JavaScript says: (onUpdateImage)" + value + "
");
}
private function onUpdateFrame(value:String = ""):void
{
output.appendText("JavaScript says (onUpdateFrmae): " + value + "
");
}
private function onUpdateMount(value:String = ""):void
{
output.appendText("JavaScript says: (onUpdateMount)" + value + "
");
}
private function onUpdateGlaze(value:String = ""):void
{
output.appendText("JavaScript says: (onUpdateGlaze)" + value + "
");
}
}
}