views:

1458

answers:

1

In ActionScript 3.0, I want to extends ClassA and implements InterfaceB. The problem comes when there is a 'data' property in both ClassA and Interface B, but of different type. I wrote,

public class MyClass extends ClassA implements InterfaceB {
    private var _data:Object;

    public function get data():Object {
        return _data;
    }

    public function set data(value:Object):void {
        _data = data;
    }
}

Flex Builder won't compile this and asks me to override the getter/setter methods as they are defined in ClassA, but overriding the data property in ClassA is not what I want. And even if I add override to both the methods, compiler complains incompatible override because the data property in ClassA is of type String.

+1  A: 

That is not possible in ActionScript 3.0. The best thing you can do is type to Object or an interface the different data types share and add assertions in the setters of the derived classes.

Christophe Herreman