Action Script 'include' statement example

Example below shows two consequent action script files: and, and the third example, i.e., Figure.mxml in our main mxml file inside which the working of 'include' statement has been demonstrated.

Action Script 'include' statement example


Example below shows two consequent action script files: and, and the third example, i.e. Figure.mxml is our main flex file inside which the working of  include statement has been demonstrated. Above mentioned action script files are in the includes folder that has been called by include statement in the main mxml file. The root directory of includes folder should match with the root directory and folders of your main mxml file and ant build file, here it is obvious that your build file and mxml file have same root directory. Now in the main mxml file, <mx:Script> tags  are made in which two include statements are used to call two action script files. Action script files posssess .as extension. For calling the files their relative paths are used. 

Syntax for using include statement:-  

 include '  ';

Action script files can also be called through the source attribute property in <mx:Script> tag, but in that case only a single action script file will be called. 
Noto : The source property and include statement cannot be used together in <mx:Script> tags. 

Syntax for using 'source' attribute:-  

<mx:Script source  =  '  '> ...... </mx:Script>

In Our first action script file, two packages flash.dispaly and mx.core has been imported for getting the instances of Sprite and UIComponent classes. Further in the code, two geometrical figures have been created and for creating these figures two Sprite type variables have been created.  Now graphics feature of Sprite class provides two static methods: .beginFill() and .drawCircle/Rect(), and among these methods the first one fills color in the figure and the second one creates the figure. Now our Sprite variables that we have created are called inside the UIComponent variable through .addChild function, now the UIComponent variable is called inside the flex Canvas container through the container's  id  property, which means figures will form inside the Canvas.

import flash.display.Sprite;
  import mx.core.UIComponent;

  public function sqrt():void{
  var num:Number = Number(Math.sqrt(2));
  bn.text = 'Square root of integer "2" is: ' + num.toString();

  public var x1:Number = 30;
  public var y1:Number = 40;
  public var z1:Number = 20;
  public var f1:Number = 50;

  public function draw():void{
  var circle:Sprite = new Sprite();;,y1,z1);

  var rectangle:Sprite = new Sprite();;, y1, z1, f1);

  var rose:UIComponent = new UIComponent();

  x1 = x1 + 40;
  y1 = y1 + 5;
  z1 = z1 + 0;
  f1 = f1 + 0

public function sqrt():void{
  var num:Number = Number(Math.sqrt(2));
  bn.text = 'Square root of integer "2" is: ' + num.toString();


<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<mx:Application xmlns:mx = ''
 creationComplete = 'sqrt();'>
  include 'includes/';
  include 'includes/';

  <mx:Button label = 'click me' click = 'draw()'/>

  <mx:Canvas id = 'canvas' width = '100%
  height = '100%' backgroundColor = 'white'>
  <mx:Label id = 'bn' color = 'green' textAlign = 'center'/>






Download the code

Share on Google+Share on Google+

Action Script 'include' statement example

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



Discuss: Action Script 'include' statement example   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
September 1, 2011
Update with Latest Version

Please update the new version then it helpful for beginners like me Please do it