Packagegraphics.geom
Classpublic class AspectRatio
InheritanceAspectRatio Inheritance Dimension Inheritance Object
Implements Geometry, Lockable

The AspectRatio class encapsulates the width and height of an object and indicates this aspect ratio.

The aspect ratio of an image is the ratio of its width to its height. For example, a standard NTSC television set uses an aspect ratio of 4:3, and an HDTV set uses an aspect ratio of 16:9. A computer monitor with a resolution of 640 by 480 pixels also has an aspect ratio of 4:3. A square has an aspect ratio of 1:1.

Note :This class use integers to specified the aspect ratio.

Example :

     import graphics.geom.AspectRatio ;
     
     var ar:AspectRatio ;
     
     trace("------ AspectRatio(320,240)") ;
     
     ar = new AspectRatio(320,240) ;
     trace(ar) ; // 4:3
     
     ar.verbose = true ;
     trace(ar) ; // [AspectRatio width:320, height:240, ratio:{4:3}]
     
     ar.lock() ;
     
     ar.width = 640 ;
     trace(ar) ; // [AspectRatio width:640, height:480, ratio:{4:3}]
     
     ar.height = 120 ;
     trace(ar) ; // [AspectRatio width:160, height:120, ratio:{4:3}]
     
     ar.unlock() ;
     
     ar.width = 320 ;
     trace(ar) ; // [AspectRatio width:320, height:120, ratio:{8:3}]
     
     trace("------ AspectRatio(1680,1050)") ;
     
     ar = new AspectRatio(1680,1050) ;
     
     trace(ar) ; // 8:5
     
     ar.verbose = true ;
     
     trace(ar) ; // [AspectRatio width:1680, height:1050, ratio:{8:5}]
     
     trace("------ AspectRatio(0,0)") ;
     
     ar = new AspectRatio(0) ;
     
     trace(ar) ; // 0:0
     
     ar.verbose = true ;
     
     trace(ar) ; // [AspectRatio width:0, height:0, ratio:{0:0}]
     



Public Properties
 PropertyDefined By
  gcd : int
[read-only] Determinates the greatest common divisor if the current object.
AspectRatio
 Inheritedheight : Number
Determinates the height value of this instance.
Dimension
  verbose : Boolean
Indicates the verbose mode used in the toString() method.
AspectRatio
 Inheritedwidth : Number
Determinates the width value of this instance.
Dimension
 InheritedZERO : Dimension
[static] Defines the Dimension object with the width and height properties set to zero.
Dimension
Public Methods
 MethodDefined By
  
AspectRatio(width:int = 0, height:int = 0, lock:Boolean = false)
Creates a new AspectRatio instance.
AspectRatio
  
clone():*
[override] Creates and returns a shallow copy of the object.
AspectRatio
 Inherited
Decreases the size by s and return its self(this).
Dimension
  
equals(o:*):Boolean
[override] Compares the specified object with this object for equality.
AspectRatio
 Inherited
getBounds(x:Number, y:Number):Rectangle
Returns a new bounds with this size with a pos.
Dimension
 Inherited
Increases the size by s and return its self(this).
Dimension
  
isLocked():Boolean
Returns true if the object is locked.
AspectRatio
  
lock():void
Locks the object.
AspectRatio
 Inherited
setSize(w:Number, h:Number):void
Sets the size of this instance.
Dimension
 Inherited
toObject():Object
Returns the Object representation of this object.
Dimension
  
toSource(indent:int = 0):String
[override] Returns the source code string representation of the object.
AspectRatio
  
toString():String
[override] Returns the string representation of this instance.
AspectRatio
  
unlock():void
Unlocks the object.
AspectRatio
Property Detail
gcdproperty
gcd:int  [read-only]

Determinates the greatest common divisor if the current object.

This property cast the width and the height Number in two int objects to calculate the value.

The floating values are ignored and convert in integers.


Implementation
    public function get gcd():int
verboseproperty 
public var verbose:Boolean

Indicates the verbose mode used in the toString() method.

Constructor Detail
AspectRatio()Constructor
public function AspectRatio(width:int = 0, height:int = 0, lock:Boolean = false)

Creates a new AspectRatio instance.

Parameters
width:int (default = 0) — The width int value use to defines the aspect ratio value.
 
height:int (default = 0) — The height int value use to defines the aspect ratio value.
 
lock:Boolean (default = false) — This boolean flag indicates if the aspect ratio must be keeped when the width or height values changes.
Method Detail
clone()method
override public function clone():*

Creates and returns a shallow copy of the object.

Returns
* — A new object that is a shallow copy of this instance.
equals()method 
override public function equals(o:*):Boolean

Compares the specified object with this object for equality.

Compares the toString() (ex:4:3) of the aspect ratio object and the passed-in object type.

Example :

         import graphics.geom.AspectRatio ;
         
         var a:= new AspectRatio( 320 , 240 ) ;
         var b:= new AspectRatio( 640 , 480 ) ;
         
         trace( a.equals( b ) ) ; // true 
         

Parameters

o:*

Returns
Booleantrue if the the specified object is equal with this object.
isLocked()method 
public function isLocked():Boolean

Returns true if the object is locked.

Returns
Booleantrue if the object is locked.
lock()method 
public function lock():void

Locks the object.

toSource()method 
override public function toSource(indent:int = 0):String

Returns the source code string representation of the object.

Parameters

indent:int (default = 0)

Returns
String — the source code string representation of the object.
toString()method 
override public function toString():String

Returns the string representation of this instance.

Returns
String — the string representation of this instance.
unlock()method 
public function unlock():void

Unlocks the object.