Hello :)

1 - in AS1 you can use addProperty with the prototype and not in the
constructor !!

// ----o Constructor

_global.Square= function(side)
{
   this.side=side
}

// ----o Public Methods

Square.prototype.getArea=function()
{
   return Math.pow(this.side,2);
}

Square.prototype.setArea = function(area)
{
    this.side=Math.sqrt(area) ; // don't forget "Math" and not "math" !!!
}


// ----o Virtual Properties

Square.prototype.addProperty("area", Square.prototype.getArea,
Square.prototype.setArea) ;

2 - In AS2 you have 2 methods to create Virtual Properties

2 - 1 with get and set keywords

class Square
{
     // ----o Constructor

    public function Square(side:Number)
    {
       this.side = side ;
    }

    // ----o Public Properties

    public var side:Number ;

    // ----o Virtual Properties

   public function get area()
   {
       return Math.pow(this.side,2);
   }

   public function set area ( area )
   {
        side = Math.sqrt(area) ;
    }

}

2 - 2 with addProperty method

class Square
{
     // ----o Constructor

    public function Square(side:Number)
    {
       this.side = side ;
    }

    // ----o Public Properties

    public var side:Number ;

    // ----o Public Methods

   public function getArea()
   {
       return Math.pow(this.side,2);
   }

   public function setArea ( area )
   {
        side = Math.sqrt(area) ;
    }

   // ----o Virtual Properties

   static private var __AREA__:Boolean = Square.prototype.addProperty("area",
Square.prototype.getArea ,Square.prototype.setArea) ;

}


EKA+ :)

2006/9/25, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:

I know AddProperty was useful in creating getter/setters when defining AS1
based classes

ie
//CODE BEGIN
//create a new square class
_global.Square= function(side){
this.side=side

this.addProperty("area",this.getArea,this.setArea);
}


Square.prototype.setArea=function(area){
this.side=math.sqrt(area);
}

Square.prototype.getArea=function(){
return Math.pow(this.side,2);
}

//CODE END

Is this same AddProperty technique useful with AS2 classes?



[e] jbach at bitstream.ca
[c] 416.668.0034
[w] www.bitstream.ca
--------------------------------------------
"...all improvisation is life in search of a style."
             - Bruce Mau,'LifeStyle'
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to