Action Script 'source' attribute example
In the example below an action script file with .as extension has been
imported in the main Operations.mxml file. This .as file instance is brought
through the source attribute in <mx:Script> tags.
Syntax for using 'source'
attribute:-
<mx:Script source
= ' '> ...... </mx:Script>
In the imported action script file four functions are defined and they are called
through the click attribute property of buttons in the main mxml file.
IncludedFile.as
public function addition(x:Number, y:Number):Number {
return x + y;
}
public function product(x:Number, y:Number):Number{
return x*y;
}
public function division(x:Number, y:Number):Number{
return x/y;
}
public function subtraction(x:Number, y:Number):Number{
return x - y;
}
|
Operations.mxml
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml'>
<mx:Script source = 'includes/IncludedFile.as'/>
<mx:TextInput id = 'value0' />
<mx:TextInput id = 'value1'/>
<mx:HBox>
<mx:VBox>
<mx:Label text = 'Addition result'/>
<mx:TextArea id = 'result'/>
<mx:Button label = 'Add'
click = "result.text = String(addition(Number(value0.text),
Number(value1.text)))"/>
<mx:Label text = 'Multiplication result'/>
<mx:TextArea id = 'result1'/>
<mx:Button label = 'Product'
click = 'result1.text = String(product(Number(value0.text),
Number(value1.text)))'/>
</mx:VBox>
<mx:VBox>
<mx:Label text = 'Division result'/>
<mx:TextArea id = 'result2'/>
<mx:Button label = 'Divide'
click = 'result2.text = String(division(Number(value0.text),
Number(value1.text)))'/>
<mx:Label text = 'Subtraction result'/>
<mx:TextArea id = 'result3'/>
<mx:Button label = 'Subtract'
click = 'result3.text = String(subtraction(Number(value0.text),
Number(value1.text)))'/>
</mx:VBox>
</mx:HBox>
</mx:Application>
|
Operations.swf
Download the code