144
CHAPTER 7
E4X
In essence, ECMAScript for XML (E4X) introduces a convenient way of manipulating and extracting
data for XML with simple regular expressions and dot notation.
Figure 7-15 shows a simple XML file called bookstore.xml.
Figure 7-15. Simple XML file
Once the XML file is loaded, you can easily access data using ActionScript notation. For example,
bookstore.book.title would give you Foundation Flex for Designers. Figure 7-16 shows a working
example that can be used to create more elaborate projects.
Figure 7-16. Working E4X example
Accessing data in this way makes working with XML much simpler and can be used to manage complex
data. This example only scratches the tip of iceberg but illustrates the purpose of E4X.
SWFLoader
SWFLoader is used to load and display other SWF files into Flex. It allows you to scale the content you
are loading, as well as monitor the loading progress (Figure 7-17).
145
ACTIONSCRIPT IN FLEX
In Figure 7-17 we use @Embed, which tells Flex to embed the asset at compile time, meaning the image
is bundled along with the final SWF. However, you may choose not use @Embed, and the compiler will
load the asset at runtime instead.
The Height and Width parameters allow you to set dimensions for the file being loaded.
Figure 7-17. SWFLoader
ActionScript and MXML
The most common and easiest way to add ActionScript to a Flex application via MXML is to type it in
the Source view of the MXML Editor. Place the ActionScript after the opening tags and before the
component tags.
Pages:
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117