ExternalEvent is a ActionScript3.0 package.It can give your swf the capability to dispatch event to javascript code.
follow 3 steps,can make your swf dispatch event In the specific time.
import the classes to your code:
import me.wentao.external.ExternalEvent;
import me.wentao.external.ExternalEventDispatcher;
write this line in your initial function:
ExternalEventDispatcher.getInstance().addExternalCall();
ExternalEvent will use flash.externalInterface.addCallback() open two function to javascript code:
addEventListener(typeName,listenerFuncName);
removeEventListener(typeName,listenerFuncName);
create a ExternalEvent and add params that you want javascript received then dispatch it to javascript,like this:
var event:ExternalEvent = new ExternalEvent("btn2click");
event.addParam("msg","i am btn2");
event.addParam("customParam",{x:1,y:2});
ExternalEventDispatcher.getInstance().dispatchEvent(event);
get the swf object:
var swfdiv = document.getElementById("swfdiv");
add event listener:
swfdiv.addEventListener("btn1click","console.log");
see example