Flash8 textAreaコンポーネントでのimgタグのバグ

↓ひとまず情報
http://play.ground.gr/?p=77
http://www.actionscript.org/forums/showthread.php3?t=85011
http://www.kirupa.com/forum/showthread.php?t=211593

■発生条件
Flash8 で textAreaにimgタグ付きのhtmlテキストを書き込んだときにバグがおきる。

■バグ現象1
html=trueとして、imgタグつきのHTMLをいれると、1回目は画像がロードされる。
しかし、同じtextAreaに再度imgタグ付きのhtmlテキストをいれると、2回目以降は画像がロードされない。


■バグ現象2
html=trueとして、imgタグつきのHTMLをいれると、textArea内では、書き替えられたタグが入っている。

↓いれたテキスト

<font size='30'>test text<img src='Dock.jpg'/></font>

↓textプロパティに入るテキスト

<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="_sans" SIZE="30" COLOR="#000000" LETTERSPACING="0" KERNING="0">test text<FONT SIZE="2"><IMG SRC="Dock.jpg"> </FONT></FONT></P></TEXTFORMAT>

この書き換えられたタグのテキストを別のtextAreaコンポーネントにいれても画像がロードされない。


★解決法
バグ現象1は、とりあえず回避不可なので、新しいtextAreaオブジェクトを再生成するという方法しかない。
バグ現象2は、全体を囲んでいる TEXTFORMATタグと Pタグを削除すればよい。

//デフォルトの深度
var depthNum = 10;
//textAreaコンポーネントに同じテキストをいれる。
//_obj は、textAreaコンポーネント限定。
function rewriteText(_obj) {
	//もとのテキストをコピーする
	var _COPYOBJ = _obj._parent[_obj._name+"_copy"];
	var moto_text = "";
	var out_text = "";
	if (_COPYOBJ._visible) {
		moto_text = _COPYOBJ.text;
		_COPYOBJ.removeMovieClip();
	} else {
		moto_text = _obj.text;
	}
	//もとのオブジェクトを非表示に
	_obj._visible = false;
	//新しいオブジェクトをつくる
	tmp_options = new Object();
	tmp_options.editable = _obj.editable;
	tmp_options.html = _obj.html;
	tmp_options.wordWrap = _obj.wordWrap;
	tmp_options.vScrollPolicy = _obj.vScrollPolicy;
	tmp_options.hScrollPolicy = _obj.hScrollPolicy;
	_obj._parent.createClassObject(mx.controls.TextArea, _obj._name+"_copy", depthNum++, tmp_options);
	//再宣言
	_COPYOBJ = _obj._parent[_obj._name+"_copy"];
	//テキストの選択可否状態のひきつぎ
	_COPYOBJ.label.selectable = _obj.label.selectable;
	_COPYOBJ.setSize(_obj.__width, _obj.__height);
	_COPYOBJ.move(_obj._x, _obj._y);
	//TEXTFORMATタグと Pタグを削除して書き出し。
	out_text = moto_text;
	out_text = out_text.slice(out_text.indexOf(">")+1, out_text.lastIndexOf("<"));
	out_text = out_text.slice(out_text.indexOf(">")+1, out_text.lastIndexOf("<"));
	_COPYOBJ.text = out_text;
	//違うフレームに移動したときに、コピーしたオブジェクトをけす
	_obj.onUnload = function() {
		_COPYOBJ.removeMovieClip();
	};
}

上記の関数で、ステージにすでに配置されているTextAreaコンポーネントのテキストを書き変える。

↓ちょっと変形版。こちらは、書き出すテキストを引数で与えるようにした。

//第2引数に書きだすテキストを加えてみた。
//最初みて、TEXTFORMATとPタグがあったら、消す
function rewriteText2(_obj, _txt) {
	//もとのテキストをコピーする
	var _COPYOBJ = _obj._parent[_obj._name+"_copy"];
	var out_text = "";
	if (_COPYOBJ._visible) {
		_COPYOBJ.removeMovieClip();
	}
	//もとのオブジェクトを非表示に
	_obj._visible = false;
	//新しいオブジェクトをつくる
	tmp_options = new Object();
	tmp_options.editable = _obj.editable;
	tmp_options.html = _obj.html;
	tmp_options.wordWrap = _obj.wordWrap;
	tmp_options.vScrollPolicy = _obj.vScrollPolicy;
	tmp_options.hScrollPolicy = _obj.hScrollPolicy;
	_obj._parent.createClassObject(mx.controls.TextArea, _obj._name+"_copy", depthNum++, tmp_options);
	//宣言
	_COPYOBJ = _obj._parent[_obj._name+"_copy"];
	//テキストの選択可否状態のひきつぎ
	_COPYOBJ.label.selectable = _obj.label.selectable;
	_COPYOBJ.setSize(_obj.__width, _obj.__height);
	_COPYOBJ.move(_obj._x, _obj._y);
	//TEXTFORMATタグと Pタグを削除して書き出し。
	out_text = _txt;
	if(out_text.slice(0,11)=="<TEXTFORMAT"){
		out_text = out_text.slice(out_text.indexOf(">")+1, out_text.lastIndexOf("<"));
	}
	if(out_text.slice(0,2)=="<P"){
		out_text = out_text.slice(out_text.indexOf(">")+1, out_text.lastIndexOf("<"));
	}
	_COPYOBJ.text = out_text;
	//違うフレームに移動したときに、コピーしたオブジェクトをけす
	_obj.onUnload = function() {
		_COPYOBJ.removeMovieClip();
	};
}

※追記
上記のスクリプトだと、複数のTEXTFORMATおよびPタグがあったときうまく動きません。もしコピペしてつかってみようという方がいたら、、その辺、要確認&カスタマイズしてご利用ください。