I’m working on a Haxe library that is being compiled to .swc so that it may be used with ActionScript 3.0 and Adobe AIR. I want to add AS3 metadata to a getter in my .swc file.
I understand that if I add @flash.property
to the property, the getter and setter will become native in AS3. In other words, this Haxe code:
private var value:Float = 0.0;
@:flash.property
public var value(get, set):Float;
private function get_value():Float {
return this._value;
}
private function set_value(value:Float):Float {
if(this._value == value) {
return this._value;
}
this._value = value;
this.dispatchEvent(new Event(Event.CHANGE));
return this._value;
}
Generates something resembling this in the AS3 .swc (I know that it’s probably a bit more complicated than that, but that’s the gist):
private var _value:Number = 0.0;
public function get value():Number {
return this._value;
}
public function set value(value:Number):void {
if(this._value == value) {
return this._value;
}
this._value = value;
this.dispatchEvent(new Event(Event.CHANGE));
}
I would like to add some AS3 metadata to the getter.
Previously, I’ve successfully added @:meta
to a class and verified that it was included in the .swc file. However, I can’t seem to get it to work with getters and setters. I’ve tried two things.
- On the property definition:
@:meta(Bindable("change"))
@:flash.property
public var value(get, set):Float;
- On the getter definition:
@:meta(Bindable("change"))
private function get_value():Float {
return this._value;
}
Neither seems to work, though. Is there another location to add @:meta
to a property that I’m missing?
I’ve also tried using the older @:getter
and @:setter
instead of @:flash.property
, but that seems to result in couple of different issues, depending on how I code it up.
- I either get strange runtime exceptions like this, when I run it in Adobe AIR:
VerifyError: Error #1053: Illegal override of MyClass in com.example.MyClass.
- Or trying to use my class in AS3 won’t compile because I get this error:
Ambiguous reference to value
I also seem to recall that I couldn’t properly implement getters/setters defined on Haxe interfaces with AS3 classes without using @:flash.property
because other Haxe code would assume that get_
and set_
functions would always be available unless @:flash.property
were specified in the interface. Asking AS3 developers to add extra methods to their classes that implement an interface in order to make Haxe happy is not ideal here, and I’d like to avoid it.
So I don’t think that I can make this work without @:flash.property
.
Any ideas?