2007-06-08

把 JavaScript 當作 temporary data pool (AS3 和 AS2 溝通)

將 SWF9(from Flex2)收到的 Flashvars 變數, 傳給 JS
SWF8 需要時或被載入後再由 JS 取出
SWF9: AS3
private var paramObj:Object;
private function init():void{
paramObj = Application.application.parameters;
ExternalInterface.call('setMyVars', paramObj);
}

JavaScript:
var myVars;
function setMyVars(v){
myVars = v;
/*
var s='';
for(var i in v){
s+= i+' : '+v[i]+'\n';
}
alert(s);
*/
}
function getMyVars(){
return myVars;
}

SWF8: AS2
import flash.external.ExternalInterface;
var myVars = ExternalInterface.call('getMyVars');

JavaScript 的 alert() 有時也是個很好的除錯工具

沒有留言:

FB 留言