Declare a constructor method for the Example class : Constructor « Class « Flash / Flex / ActionScript






Declare a constructor method for the Example class

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var example:Example = new Example(  );
        trace(example.getId(  )); // Displays: Example Class
    }
  }
}
class Example {
        private var _id:String;
        public function Example(  ) {
            _id = "Example Class";
        }
        public function getId(  ):String {
            return _id;
        }
    }

        








Related examples in the same category

1.Creating a Constructor
2.Add public attribute to contrustor.
3.A class named Product with a constructor and a method
4.Constructor with parameter
5.Add assignment code to class constructor
6.Set the memeber variable in constructor