Advertisement
azrafe7

Haxe SWC override getter/setter

Dec 18th, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // in Haxe I have this:
  2.  
  3. // MyRect.hx
  4.     #if swc @:extern #end
  5.     public var width(get, set):Int;
  6.  
  7.     #if swc @:getter(width) #end
  8.     private function get_width() { return Std.int(rect.width); }
  9.  
  10.     #if swc @:setter(width) #end
  11.     private function set_width(value:Int):Int { throw new Error("Cannot modify this property!"); return 0; }
  12.    
  13. // MyObject.hx
  14.     private var _width:Int = 0;
  15.  
  16.     //#if swc @:getter(width) #end
  17.     override private function get_width() { return _width; }
  18.  
  19.     //#if swc @:setter(width) #end
  20.     override private function set_width(value:Int):Int
  21.     {
  22.         if (_width != value) {
  23.             _width = value;
  24.             update();
  25.         }
  26.         return value;
  27.     }
  28.  
  29. // It compiles fine as a SWC (no compiler errors). But when I try to use the lib in AS3 I get:
  30. // VerifyError: Error #1053: Illegal override of width in net.test.MyObject
  31. //
  32. // I've tried removing the override, or the getter/setter to no avail.
  33. //
  34. // Using extern/getter/setter has worked fine in other tests, but every time I used an override
  35. // I get the mentioned error and don't know how to work around it.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement