COMMUNITY

Why am I getting "the method required by property is missing"?


(Chrisvelevitch) #1

My class contains:-

    public static var focus(get, set) : IFocusDisplayObject;

and:-

    public static function get_focus() : IFocusDisplayObject
    {
        var manager : IFocusManager = getFocusManagerForStage(Starling.current.stage);
        if (manager != null)
        {
            return manager.focus;
        }
        return null;
    }

    public static function set_focus(value : IFocusDisplayObject) : IFocusDisplayObject
    {
        var manager : IFocusManager = getFocusManagerForStage(Starling.current.stage);
        if (manager == null)
        {
            throw new Error(FOCUS_MANAGER_NOT_ENABLED_ERROR);
        }
        manager.focus = value;
        return value;
    }

So why is the compiler complaining about it?

Using: openFl compiler and targeting HTML5.


#2

Doesn’t the property need to be defined like this?

public static var focus(default, default) : IFocusDisplayObject;

I’m new to Haxe and trying to speed learn so I might be wrong but I just tried it in my own code and seems to work :smile:

EDIT: No, that is clearly wrong - ignore me!


#3

This is the way it works it I think:

@:isVar public var somevar(get, set) :Int;

Ref: https://haxe.org/manual/class-field-property-rules.html