Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Flex Action Script 'source' attribute example

Related Tutorials


 
 

Share on Google+Share on Google+

Action Script 'source' attribute example

Advertisement
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. 

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

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: September 9, 2008

Related Tutorials

Discuss: Action Script 'source' attribute example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com