Properties getter/setter ( flash target)

83 views
Skip to first unread message

MJ

unread,
Apr 8, 2014, 9:13:52 AM4/8/14
to haxe...@googlegroups.com
Hi everyone, 
 I'm new in haxe development and I have strange problem with getter/setter methods. I compile with command " haxe -swf myswf.swf Main -D as3-native -D swf-protected" , below is my test code in haxe

import flash.display.Sprite;

class Main extends Sprite {

  public var radius(get, set):Float;
  private var _radius:Float = 10;

  function get_radius():Float { return _radius; }
  function set_radius(value:Float):Float  {   return _radius = value;   }


   public function new () {
      radius = 20;
      trace("Radius: "+radius);
   }
}

After compile to swf I do not have access to variable radius . I decompile with http://www.showmycode.com/  and this is what I saw:

import haxe. * ;
import flash.display. * ;
public class Main extends Sprite {

    protected var _radius: number;

    public function Main() : void {
        _radius = 10;
        super();
        set_radius(20);
    }
    protected function set_radius(_arg1: number) : number {
        var _local2: number = _arg1;
        _radius = _local2;
        return (_local2);
    }
    protected function get_radius() : number {
        return (_radius);
    }
}
 So what is strange for me . Variable radius is missing. Getter and setter have been set as funcition : "set_radius"  and "get_radius()" and not the correct ones "function set  radius(..)" and "function get radius()" in AS3. Is this normal behavior for haxe to swf or is some kind of bug ?

Simon Krajewski

unread,
Apr 8, 2014, 9:17:56 AM4/8/14
to haxe...@googlegroups.com
It's normal because you're using Haxe properties, not Flash ones. The
physical radius field is omitted because it is not needed, as documented
here:
https://github.com/HaxeFoundation/HaxeManual/blob/master/md/manual/class-field-property-rules.md#define-physical-field

There's a flash-specific @:getter/@:setter feature which I don't want to
explain because I consider it bad practice in the Haxe world (unless you
are overriding externs).

Simon

MJ

unread,
Apr 8, 2014, 12:59:21 PM4/8/14
to haxe...@googlegroups.com
Thank you for you help to understanding haxe.
Reply all
Reply to author
Forward
0 new messages