152
Chapter 8: Working with Text
Embedding images, SWF files, and movie clips in text fields
In Flash Player 7 and later, you can use the
<img>
tag to embed JPEG files, SWF files, and movie
clips inside dynamic and input text fields. (For a full list of attributes for the
<img>
tag, see
“Image tag (<img>)” on page 149
.)
By default, Flash displays media embedded in a text field at full size. To specify dimensions for
embedded media, use the
<img>
tags’s
height
and
width
attributes. (See
“Specifying height and
width values” on page 152
.)
In general, an image embedded in a text field appears on the line following the
<img>
tag.
However, when the
<img>
tag is the first character in the text field, the image appears on the first
line of the text field.
Embedding SWF and JPEG files
To embed a JPEG or SWF file in a text field, specify the absolute or relative path to the JPEG or
SWF file in the
<img>
tag’s
src
attribute. For example, the following code inserts a JPEG file
that’s located in the same directory as the SWF file.
textField_txt.htmlText = "<p>Here’s a picture from my last vacation:<img
src='beach.jpg'>";
Embedding movie clip symbols
To embed a movie clip symbol in a text field, you specify the symbol’s linkage identifier for the
<img>
tag’s
src
attribute. (For information on defining a linkage identifier, see
“Attaching a
movie clip symbol to the Stage” on page 127
.)
For example, the following code inserts a movie clip symbol with the linkage identifier
symbol_ID
.
textField_txt.htmlText = "<p>Here’s a movie clip symbol:<img
src='symbol_ID'>";
In order for an embedded movie clip to display properly and completely, the registration point for
its symbol should be at point (0,0).
Specifying height and width values
If you specify
width
and
height
attributes for an
<img>
tag, space is reserved in the text field for
the JPEG file, SWF file, or movie clip. After a JPEG or SWF file has downloaded completely it is
displayed in the reserved space. Flash scales the media up or down according to the
height
and
width
values.
If you don’t specify
height
and
width
values, no space is reserved for the embedded media. After
a JPEG or SWF file has downloaded completely, Flash inserts it into the text field at full size and
rebreaks text around it.
Controlling embedded media with ActionScript
Flash Player creates a new movie clip for each
<img>
tag and embeds that movie clip within the
TextField object. The
<img>
tag’s
id
attribute lets you assign an instance name to the movie clip
that is created. This lets you control that movie clip with ActionScript.
The movie clip created by Flash Player is added as a child movie clip to the text field that contains
the image.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...