8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IE で ExternalInterface を使った時のバグ対処法

Posted at

なんか最近 FlashPlayer がアップデートされて
IE で ExternalInterface を使った時に文字化けするという話をよく聞くので少し調べてみた。

※ 明らかなバグだと思うのでそのうち直るだろうけど気持ち悪いので

条件

  • IE 用のFlashPlayer
  • ExternalInterface.call を使用して JS を呼んでいる
  • 引数にマルチバイト文字列が含まれている

現象

  • 文字化け
  • 文字化けによりJSエラー

対処法

JS にマルチバイト文字列を渡さない

マルチバイトかどうかは

if (/^[^\u0001-\u007D]+$/.test(text)) 
{
	trace("マルチバイトがふくまれてるよ");
}

こんなんでざっくりチェックが出来る。
かなり適当だけど化けそうな文字が判定できればいいのでよしとする。

でも日本語渡したい

って人は IE だけ少し特別な処理にする。

if (ExternalInterface.call("window.navigator.userAgent.toLowerCase").indexOf("msie") >= 0)
{
	// IE 用の処理
}

って感じに IE を分ける。
中ではどんなことをするかというと

var objectID: String = ExternalInterface.objectID;
var functionName: String = "moja";
var param: String = "\"あいうえお\"";
navigateToURL(new URLRequest(
	"javascript:document.getElementById('" + 
	objectID + "').SetReturnValue(eval('try{__flash__toXML(" + 
	functionName + "(" + param + "));}catch(e){\"<undefined/>\";}'))"
), "_self");

こんな感じでやると普通に日本語も渡せた。

問題点

この方法で呼ぶと

var res:String = ExternalInterface.call("moja");

のように戻り値を受け取ることが出来ない。

でも戻り値ほしい

AS側から Base64 でエンコードしたやつを ExternalInterface.call で渡す。
そのへんから Base64 をデコードできるやつを拾ってきて JS 側で Base64 をデコードする。


気が向いたら他にも調べてみる。

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?