//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/swf lash.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");
}