tohokuaikiのチラシの裏

技術的ネタとか。

FlashからExternalInterfaceでJavaScriptをcallしようとしてIEでハマった件

なんか、IE9でうまく動作してなくて、デバッガ起動させたらコンソールにエラーが出てた。

Object doesn't support property or method 'SetReturnValue'

このエラーなんぞーって思って調べたら、ここに

I've found that, for IE, calling Javascript from ActionScript, I've needed to supply an "id" attribute to the object tag. The IE way of handling ExternalInterface.call(...) is to call a method on the object. IE issues the code

document.getElementById("...").SetReturnValue(...)

Without an id attribute on your object tag, this reduces to

document.getElementById("").SetReturnValue(...)

which tries to call SetReturnValue on a null object.

Note that the "id" attribute isn't required for other browsers but doesn't really hurt either.

Something similar may be happening in your case: Perhaps a "name" attribute on the embed may help.

つまり、内部的にIEはdocument.getElementById()でExternalInterfaceを呼んでいるので、にIDを与えないと失敗するよということ。

デバッガでその場所を見てみると

という感じになってた。そう。SWFObjectでラップするDIVとObjectタグに同じIDを発行してた。


ここを変えてやるとうまく行った。