How to add MovieClip (Image) to TextField in Action script 3 Flash Professional CS6

  October 20, 2012   by:  muni   No Comment

In action script 3 adding images and movie clips to the TextField very easy using <img> tag and htmlText property of TextField. Just follow few steps to add images or movieclips to the TextField.

step 1: Initialize TextField instance using TextField Class, and assign font, text size and color to the TextField using TextFormat Class.

Step 2: Now add image or movie clip to TextField using <img> tag by referring image name in src property of theĀ  <img> tag.

<img src=’eye.jpg’ width=’190′ height=’200′>

example.

var img:String= “<img src=’eye.jpg’ width=’190′ height=’200′><br/’><p> This is nice photograph</p> “;
txt_field.htmlText=img;

Note: If you want to add movie Clip to text field just mention movieclip name in the src property of the <img> tag. Like if you have MovieClip named car just refer that MovieClip like below

<img src=’car’ width=’190′ height=’200′>

How to add MovieClip (Image) to TextField in Action script 3 Flash Professional CS6
import flash.display.MovieClip;
import flash.text.*;

var txt_field:TextField = new TextField;
txt_field.border=true;
txt_field.wordWrap=true;
txt_field.multiline=true;
txt_field.background=true;
txt_field.width=200;
txt_field.height=250;

var format:TextFormat = new TextFormat();
format.font = "Verdana";
format.size = 15; 

txt_field.defaultTextFormat=format;

var img:String= "<img src='eye.jpg' width='190' height='200'><br/><p> This is nice photograph</p> ";

txt_field.htmlText=img;

addChild(txt_field);