Introduced in the Flash Player 7 is the ability to embed images as well as SWF files right into dynamic text fields. This is accomplished with the use of the <img> tag. And as you can see, because the files are brought in by means of an HTML tag, the text fields must be HTML-enabled. The <img> tag has several attributes that can be changed and manipulated:
Those are all the attributes for the <img> tag, so let's go over an example of loading in an image:
The preceding code simply sets the htmlText property of the text field to the text we want to display, plus the image tag that will embed the image. Test the movie, and you will see a text field with an image and some text in it as shown in Figure 19.9. Figure 19.9. Embedding images into text fields is a great way to liven up boring text.To continue with this example, we are going to embed the clock SWF file under the image.
This line of code adds the clock.swf file to the text field, as well as some more text. Test the movie again, and now you will see the clock in the text field as well as the image, as in Figure 19.10. Figure 19.10. You can also embed external SWF files right into text fields.Now we have embedded files into text fields. What if we want to manipulate them? Manipulating Embedded Content in Text FieldsYou can control embedded content in text fields using the id attribute within the <img> tag. You simply give the movie clip that is containing the embedded content an instance name, and then you can refer to it in ActionScript. Follow these steps continuing from the preceding example:
The preceding code uses the <img> tag to place a SWF file in the text field along with some text. Then we create a callback function that will fire continually, thereby sending the result of the getTimer() function to the text field constantly. Test the movie and you will see the text field within the text field constantly being updated by the getTimer() method. We have covered a lot of different ways you can bring content into Flash, but so far, all the examples we have used have brought content into Flash while Flash was running locally on our computer. This means that the transfer has been almost instant. In the real world, this would not be the case because SWFs and images take time to load, and that's where preloaders come in. |