比较常用的,AS 调用 JS
- private function callJS():void{
- ExternalInterface.addCallback("callbackQQPay",callBackFromJs);
- var obj:Object = {};
- obj.id = 1;
- ExternalInterface.call("testItem", obj);
- }
- private function callBackFromJs(obj:Object=null):void{
- trace("OK!");
- }
在 JS 调用 AS 时 需要考虑到 浏览器的兼容性
- function testItem(p){
- var swfName = "网页中swf的名字";
- var flash = thisMovie(swfName);
- flash.callbackQQPay('OK');
- }
- //查找网页中的swf
- function thisMovie(movieName) {
- if (window.document[movieName])
- {
- return window.document[movieName];
- }
- if (navigator.appName.indexOf("Microsoft")==-1)
- {
- if (document.embeds && document.embeds[movieName])
- return document.embeds[movieName];
- }
- else
- {
- return document.getElementById(movieName);
- }
- }
转帖自:斯樵工坊