Copy link to clipboard
Copied
I have to repost it. Wondering what adobe will say about it.
I have tried this for a couple of days. I created a swf object in window.onload (also tried to create it directly while the script was loaded ), then call an AS function from JS. statically embedded swf works for both IE8 and FF, FF also fine for dynamically loading. In IE, this call externalinterface.call("echo", "as returns " + b); always shows "as returns false". The callback function has never worked in other approches with dynamic creation. Anyone has good experience?
Thanks.
//js
<script language="javascript">
var containerready=false,flashready=false;
function addLoadEvent(func) {var oldonload = window.onload; if (typeof window.onload != 'function') {
window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); }}
}
function embedswf(){
var a,swf="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'";
swf+=" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0'";
swf+=" width='215' height='318' id='testswf1' align='middle'>";
swf+=" <param name='allowScriptAccess' value='always' />";
swf+=" <param name='allowFullScreen' value='false' />";
swf+=" <param name='movie' value='testswf1.swf' />";
swf+=" <param name='quality' value='high' />";
swf+=" <param name='wmode' value='transparent' />";
swf+=" <embed src='testswf1.swf' quality='high' wmode='transparent' width='215' height='318' name='testswf1' align='middle' allowScriptAccess='always' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' /></object>";
a=document.createElement("div");
a.id="swfholder";
a.innerHTML=swf;
document.body.appendChild(a);
containerready=true;
window.setTimeout(callas, 100);
}addLoadEvent(embedswf);function echo(p){ alert(p)} function callas()
{
// alert("callas:containerready="+containerready+";fl ashready="+flashready);
containerready=true;
if(flashready){
var a=getswf();
a&&(a.flashfunc())
return
}
window.setTimeout(callas, 100);
}function setflashready()
{
flashready=true;
}
function getcontainerready()
{
//alert("getcontainerready:g31="+containerready+";fl ashready="+flashready);
return containerready;
}
function getswf()
{
if (navigator.appName.indexOf("Microsoft") != -1)
return window["testswf1"];
else
return document["testswf1"];
}</script>//as
import flash.external.ExternalInterface;flash.system.Security.allowDomain("*");var rtm:Timer = new Timer(500);
startTest();function f0():void {
ExternalInterface.call("echo", "one");
}
function timerHandler(event:TimerEvent):void
{
if (isContainerReady())
{
rtm.stop();
rtm.removeEventListener(TimerEvent.TIMER, timerHandler);
setupCallbacks();
}
}
function startTest():void
{
if (ExternalInterface.available)
{
try
{
if (isContainerReady())
{
setupCallbacks();
}
else
{
rtm.addEventListener(TimerEvent.TIMER, timerHandler);
rtm.start();
}
}
catch(error:Error) {
trace("An Error occurred: " + error.message + "\n");
}
}
else
{
trace("External interface is not available for this container.");
} }
function isContainerReady():Boolean
{
var b:Boolean = ExternalInterface.call("getcontainerready");
ExternalInterface.call("echo", "as returns " + b);
return b;
}function setupCallbacks():void
{
ExternalInterface.call("echo","setupcallback");
ExternalInterface.addCallback("flashfunc", f0);
ExternalInterface.call("setflashready");
}
Copy link to clipboard
Copied
has it ever worked or is an Adobe bug? anyone knows?