OK、これを整理するのに数時間費やしましたが、Flash と Flex で動作するようになりました。
TextField に画像を表示する
<img />
MovieClip、Sprite、埋め込み画像などのTextField タグに DisplayObject をロードできます。
フラッシュの例
簡単な例です。すべてのコードはメイン タイムラインにあります。
ステージ上に動的 TextField を作成します。便利な名前を付けてください。私は mine と呼んでいtxtImageTest
ます。
300x150pxtxtImageTest
などの適切なサイズにサイズ変更します。
新しい MovieClip シンボルを作成し、クラス名を付けimageClip1
ます。
新しいクリップに何かを描画するか、埋め込み画像を 内に配置しimageClip1
ます。
メイン タイムラインに戻り、すべてのオブジェクトの選択を解除して、最初のフレームで Actionscript エディターを開きます。
テキスト フィールドで複数行とワード ラップを有効にします。
imageClip1.wordWrap = true;
imageClip1.multiline = true;
imageClip1.htmlText = "<p>You can include an image in your HTML text with the <img> tag.</p><p><img id='testImage' src='imageClip1' align='left' width='30' height='30' hspace='10' vspace='10'/>Here is text that follows the image. I'm extending the text by lengthening this sentence until it's long enough to show wrapping around the bottom of the image.</p>"
ムービーを保存してテストします。
フレックスの例
Flash で行ったようにライブラリで新しいムービークリップを作成することはできないため、同じタスクを実行する新しいクラスを作成する必要があります (ライブラリで新しいクリップを作成する場合、この方法は Flash でも機能します)。 .
BlackArrow.as と呼ばれる黒い三角形の弾丸のクラスを次に示します。
// Set the correct package for you class here.
package embed
{
import flash.display.Sprite;
import mx.core.BitmapAsset;
public class BlackArrow extends Sprite
{
// Embed the image you want to display here.
[Embed(source='assets/embed/triangleIcon_black.png')]
[Bindable]
private var TriangleImage:Class;
public function BlackArrow()
{
super();
// Instantiate the embedded image and add it to your display list.
var image:BitmapAsset = new TriangleImage();
addChild(image);
}
}
}
注: Bitmap (Flash の場合) または BitmapAsset (Flex の場合) を拡張しないでください。TextField で適切にスケーリングまたは配置されないためです。スプライトまたは類似のものを選択します。
この画像を TextField に表示するクラスの例を次に示します。
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%">
<mx:Script>
<![CDATA[
import embed.BlackArrow;
// You must include a variable declaration of the same type as your
// wrapper class, otherwise the class won't be compiled into
// the SWF and you will get an IOError.
private var img2:BlackArrow;
]]>
</mx:Script>
<mx:Text id="txtResults1" width="100%" height="100%">
<mx:htmlText>
<![CDATA[<p>You can include an image in your HTML text with the <img> tag.</p><p><img id='testImage' src='embed.BlackArrow' align='left' hspace='10' vspace='10'/>Here is text that follows the image. I'm extending the text by lengthening this sentence until it's long enough to show wrapping around the bottom of the image.</p>]]>
</mx:htmlText>
</mx:Text>
</mx:VBox>
src
image タグの属性で完全修飾クラス名を使用していることに注意してください。
ファイナルノート