To build a Flex application, you need to use a combination of MXML and ActionScript 3.0 languages. For example, you may use MXML to layout and design your user interfaces and write business logic in ActionScript. This is a common practice followed by Flex developers. In this section, we will see how to mix ActionScript and MXML to build Flex applications.
There are two ways to include an ActionScript file in your Flex application:
With the help of the
<mx:script>
tagWith the help of the
include
statement
In the Flex development environment, you can add ActionScript code in MXML file by using the<mx:script>
tag. See the following example:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> <mx:Script> <![CDATA[ private var color:String = "red"; private function calculateSum(x:Number, y:Number):Number { return x+y; } ]]> </mx:Script...