問題Javascript什麼時候可以開始調用Actionscript?
是否有非輪詢的方式爲Javascript命令閃存權當它的外部接口準備好了嗎?
背景
在ActionScript中,我已經註冊了一個功能的Javascript調用:
ExternalInterface.addCallback('doStuff", this.doStuff);
我用SWFObject將Flash嵌入到我的網頁:
swfobject.embedSWF(
'flash/player.swf',
'flashPlayer',
'100%',
'100%',
'9',
'expressInstallSwfTODO.swf',
{},
{allowfullscreen: true},
{},
function(status) {
if (!status.success) {
alert('Failed to embed Flash player');
} else {
$('flashPlayer').doStuff();
}
}.bind(this)
);
當Flash通過回調成功嵌入時,SWFObject允許您運行代碼。我嘗試在此回調中運行$('flashPlayer')。doStuff,但它聲稱它未定義。看來Flash需要一些時間來啓動它的外部接口。所以我一直在使用輪詢攻擊來找出外部接口什麼時候準備就緒:
new PeriodicalExecutuer(
function(poller) {
if ($('flashPlayer').doStuff) {
$('flashPlayer').doStuff();
poller.stop()
}
},
0.2
);
這個輪詢器並不理想。在doStuff的執行過程中存在視覺上可察覺的延遲,並且它使我的整體代碼結構變得模糊。
的onload會平滑但速度較慢。拿你的選擇。 – 2011-01-22 23:49:14