Share on Google+Share on Google+

Action Script 'source' attribute example

In the following example, an action script file with .as extension has been imported in the main 'Operations.mxml' file. The '.as' file instance is brought through the 'source' attribute in tags.

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.

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; 


<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<mx:Application xmlns:mx = ''>
  <mx:Script source = 'includes/'/>

  <mx:TextInput id = 'value0' />
  <mx:TextInput id = 'value1'/>


  <mx:Label text = 'Addition result'/> 
  <mx:TextArea id = 'result'/>

  <mx:Button label = 'Add
click = "result.text = String(addition(Number(value0.text),

  <mx:Label text = 'Multiplication result'/> 
  <mx:TextArea id = 'result1'/>
  <mx:Button label = 'Product
click = 'result1.text = String(product(Number(value0.text),

  <mx:Label text = 'Division result'/> 
  <mx:TextArea id = 'result2'/>

  <mx:Button label = 'Divide
click = 'result2.text = String(division(Number(value0.text),

  <mx:Label text = 'Subtraction result'/> 
  <mx:TextArea id = 'result3'/>
  <mx:Button label = 'Subtract
click = 'result3.text = String(subtraction(Number(value0.text),




Download the code


Posted on: September 9, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Action Script 'source' attribute example  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image