Reputation: 21924
Is there a way to override the width (for a getter) on a Sprite?
I see examples of how to override the setter but not the getter
I need to do something like
override public function get width():Number {
if (onecase) {
return this width;
} else {
return another width;
}
}
Upvotes: 0
Views: 2151
Reputation: 17217
the setter/getter method signatures need to be identical since ActionScript 3.0 doesn't support function overloading. the x, y, width and height properties of display objects are Number objects, not int as one might assume.
//Class Properties
private var widthProperty:Number;
~
//Set Width
override public function set width(value:Number):void
{
widthProperty = value;
}
//Get Width
override public function get width():Number
{
return widthProperty;
}
Upvotes: 1
Reputation: 429
Yes you can.
override public function get width():Number {
if (onecase) {
return myWidth;
} else {
return super.width;
}
}
super.width is will be basic Sprite getter.
Upvotes: 2