You use the source attribute of the <mx:Script> tag to include external ActionScript files in your Flex applications. This provides a way to make your MXML files less cluttered and promotes code reuse across different applications.
The following example shows the contents of the IncludedFile.as file:
public function computeSum(a:Number, b:Number):Number {
return a + b;
}
The following example imports the contents of the IncludedFile.as file. This file is located in the same directory as the MXML file.
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"><mx:Script source="IncludedFile.as" /><mx:TextInput id="ta1st" text="3"/> <mx:TextInput id="ta2nd" text="3"/> <mx:TextArea id="taMain"/> <mx:Button id="b1" label="Compute Sum"
click="taMain.text=computeSum(Number(ta1st.text), Number(ta2nd.text))"/> </mx:Application>
The source attribute of the <mx:Script> tag supports both relative and absolute paths. For more information, see Referring to external files.
You cannot use the source attribute and wrap ActionScript code inside the same <mx:Script> tag. To include a file and write ActionScript in the MXML file, use two <mx:Script> tags.
Version 1.5
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00000050.htm