This is done through a repeater,
which we discuss in the next section.
Getting the computer to do the work: repeaters
A repeater is a piece of code that allows you to do a similar step many times. In this case, the similar
step is the creation of a thumbnail image, and placing an image from our XML into it. For those with
programming experience, this is a form of the for loop.
In this example, we want to repeat the image and the HBox that helps us format it. So we put a
repeater tag around these two objects in the Source view. The tag looks like this;
id="imageRepeater">
horizontalAlign="center">
verticalAlign="middle"/>
Note that the first part of the tag goes before the code that you want to repeat, the HBox in our case,
and the closing tag goes after it. The dataProvider is set up based on the structure of our XML file.
This setup pulls in the data and keeps repeating until it hits the end of the XML.
By adding this tag to your MXML, you should end up with something that looks like Figure 8-21.
166
CHAPTER 8
Figure 8-21. MXML with a repeater
We use the repeater to create each thumbnail image. As each thumbnail is created, the latest image is
added to it. This can be done in either the Design or Source view, but we??™ll show it in the Design view
so that it is more visual.
Pages:
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129