Including ActionScript Code In A Flex Application Using the mx:script Tag's Source Attribute

For many of my Flex applications I have a large block of ActionScript code within the main application MXML file. For example see: http://www.stfm.org/flex/relateComboBoxes/bin/relateComboBoxes.html (right click on the app to view the source).

The ActionScript code usually consists of some import statements, variable declarations, and function definitions. I've often wondered how I could put all of the ActionScript code in a separate file to make my source code more organized.

By chance I came across a discussion about the basic mx:script tag and found out it has a source attribute. You can place your ActionScript code into a separate ActionScript file and then use the source attribute to include the separate ActionScript file into your MXML file.

For example:

<mx:Script source="findPeopleAS.as">

</mx:Script>

Visit the Using ActionScript reference in the Flex 2.0 Developer's Guide for further details Be sure to note that you should not name your separate ActionScript file with the same name as your MXML file and that you cannot include an ActionScript class using the source attribute.

Comments
What is your opinion on code behind approach?

It works for me
http://www.flashcomguru.com/index.cfm/2007/1/10/Us...
# Posted By JabbyPanda | 2/13/07 5:15 AM
Jabby - thanks for the information about the code behind approach.

As I become more advanced in Flex, using the code behind technique will be something I try. Aral's example was a bit complicated since he over rode many of the event handling functions and extended all the classes.

I'll need to start with a simpler code behind example to learn the technique.
# Posted By Bruce | 2/13/07 5:48 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.