Writing the drag-and-drop functions
To control the drag-and-drop in Flex, we need to create the functions that spell out what we want to
do. This is done through ActionScript.
The code is provided as a text file with this chapter??™s download files, but let??™s walk through to see how
it all works. Jump to the Source view of your project as this is where all ActionScript goes.
ActionScript is generally placed within the tags (Figure 9-25).
Figure 9-25. Script tags
The code provided in the text file dragAndDropCode replaces the code that was in these tags previously.
This code is generally placed in the MXML file before the MXML tags.
The first piece of code (Figure 9-26) brings in the classes that will be used later.
Figure 9-24. Adding the drag functions
Figure 9-23. Naming the
VideoDisplay component
190
CHAPTER 9
Figure 9-26. Imported classes
Importing just the classes that are needed, as opposed to all possible classes, helps keep the file sizes
small. In this case, we are importing the classes used to control the components we use (namely,
VideoDisplay and Panel) and the classes that we use to specify what we want our dragging to do.
The next piece of code creates our dragIt function (Figure 9-27). This is the function that we connected
to our video thumbnail through its mouseMove property earlier.
Figure 9-27. Dragging function
191
FLEX VIDEO GALLERY WITH DRAG-AND-DROP
This function does a variety of things to control the drag-and-drop of the videos.
Pages:
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142