To separate the ActionScript from the MXML components, place the ActionScript
within
tags (Figure 7-18).
Figure 7-18. Placing ActionScript in Flex
This approach requires less direct typing of code than it appears to at first glance. By entering the start
of a tag for you, Flex attempts to give you the options that begin with what you are typing. So typing
146
CHAPTER 7
Figure 7-19. Options for an MXML tag provided while typing
Close the tag by typing >, as shown in Figure 7-20, and press Enter. Notice in
Figure 7-20 that some extra code has been added automatically.
This piece of code creates a character data section. In this section, everything
you type will not be part of an MXML tag. This is where we place our
ActionScript code.
Importing ActionScript classes into Flex
Another thing worth noting is that it is easy just to add a .* to the end of a package path, but this
throws up a few issues. First, other developers may not know exactly which class you have imported
from that package if the code is particularly complex or abstract. Second, the compiler will go through
every class in that package and check to see if it was used, which slows down the compiler. Although
the slowdown is not an issue on a small project, it can be tiresome on large builds.
Often the first pieces of code that are added are the import statements. The import statements indicate
to the compiler that you are going to declare an instance of the class you have imported.
Pages:
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118