Override existing AS3 classes
Posted
by purga
on Stack Overflow
See other posts from Stack Overflow
or by purga
Published on 2010-05-23T14:08:36Z
Indexed on
2010/05/23
14:10 UTC
Read the original article
Hit count: 129
actionscript-3
|as3
For a custom derived class "Vector2" from flash.geom.Point, when trying to override the clone() method (similar to add(), subtract() methods that will return the type itself), it will always complain about incompatible overriding 'cuz the return type has been altered from "Point" to "Vector2".
import flash.geom.Point;
public class Vector2 extends Point
{
//Constructor is good
public function Vector2(x:Number = 0, y:Number = 0)
{
super(x,y);
}
// Error: Incompatible overriding
override public function clone():Vector2 //return type has to be "Point"
{
return new Vector2(this.x , this.y);
}
}
How can we correctly reuse/override the methods provided by the super classes as supposed to create our own one (e.g. : a new clone1() method), or simply we just can't?
Thanks.
© Stack Overflow or respective owner