Writing a static block in Flex or Action Script 3

In a single sentence write the code in your class directly, it will goes under static block execution :) , sounds simple, Yes it is, typically in java to initialize static variable/ to execute some statments we need to write in this way.

public class myclass{
static{
//some statements here
}
//some variables declared here
//some functions defined here
}

Where as in Action Script 3

public class myclass{
//can write static statements here

//some variables declared here
//some functions defined here
}

Just see the example code here

package
{
import mx.controls.Alert;

public class Test
{
public static var i:int = 0;
public function Test()
{
trace(“common what you want test here “+i);
}
//static block
{
Alert.show(“Oh yes “+i);
i+=1;
}

}
}

Share and Enjoy:
  • del.icio.us
  • Facebook
  • co.mments
  • DZone
  • IndianPad
  • MySpace
  • StumbleUpon
  • Technorati
  • Twitter

Tags: , ,

Leave a comment