Yes i tried override. But it says error for openfl test flash
package net.sourceskyboxer.components;
import openfl.display.DisplayObjectContainer; import openfl.display.Sprite; import openfl.events.Event;
/** * ... * @author Jens Eckervogt */
class Component extends Sprite { private var _width:Float = 0; private var _height:Float = 0; private var _tag:Int = -1; private var _enabled:Bool = true; public static var DRAW:String = "draw";
/** * @param parent * @param xpos * @param ypos */ public function new(parent:DisplayObjectContainer = null, xpos:Float = 0, ypos:Float = 0) { super(); setMove(xpos, ypos); init(); if (parent != null) { parent.addChild(this); } } private function init():Void { addChildren(); invalidate(); } private function addChildren():Void { } private function invalidate():Void { draw(); addEventListener(Event.ENTER_FRAME, onInvalidate); } /** * * @param xpos * @param ypos */ public function setMove(xpos:Float, ypos:Float):Void { x = Math.round(xpos); y = Math.round(ypos); } /** * * @param w * @param h */ public function setSize(w:Float, h:Float):Void { _width = w; _height = h; dispatchEvent(new Event(Event.RESIZE)); invalidate(); } public function draw():Void { dispatchEvent(new Event(Component.DRAW)); } private function onInvalidate(evt:Event):Void { removeEventListener(Event.ENTER_FRAME, onInvalidate); draw(); } /** * getters and setters */ public var width(get, set):Float; override public function set_width(w:Float):Float { return w = _width; invalidate(); dispatchEvent(new Event(Event.RESIZE)); } override public function get_width():Float { return _width; } public var height(get, set):Float; override public function set_height(h:Float):Float { return h = _height; invalidate(); dispatchEvent(new Event(Event.RESIZE)); } override public function get_height():Float { return _height; } public var tag(get, set):Int; public function set_tag(value:Int):Int { return value = _tag; } public function get_tag():Int { return _tag; } public var x(default, null):Float; override public function set_x(value:Float):Float { return value = Math.round(x); } public var y(default, null):Float; override public function set_y(value:Float):Float { return value = Math.round(y); } public var enabled(get, set):Bool; public function set_enabled(value:Bool):Bool { return value = _enabled; mouseEnabled = mouseChildren = _enabled; tabEnabled = value; alpha = _enabled ? 1.0 : 0.5; } public function get_enabled():Bool { return _enabled; } }
Output:
net/sourceskyboxer/components/Component.hx:95: characters 8-34 : Redefinition of variable width in subclass is not allowed. Previously declared at flash.display.DisplayObject net/sourceskyboxer/components/Component.hx:110: characters 8-35 : Redefinition of variable height in subclass is not allowed. Previously declared at flash.display.DisplayObject net/sourceskyboxer/components/Component.hx:138: characters 8-35 : Redefinition of variable x in subclass is not allowed. Previously declared at flash.display.DisplayObject net/sourceskyboxer/components/Component.hx:146: characters 8-35 : Redefinition of variable y in subclass is not allowed. Previously declared at flash.display.DisplayObject net/sourceskyboxer/components/Component.hx:119: lines 119-122 : Field get_height is declared 'override' but doesn't override any field net/sourceskyboxer/components/Component.hx:104: lines 104-107 : Field get_width is declared 'override' but doesn't override any field net/sourceskyboxer/components/Component.hx:112: lines 112-117 : Field set_height is declared 'override' but doesn't override any field net/sourceskyboxer/components/Component.hx:97: lines 97-102 : Field set_width is declared 'override' but doesn't override any field net/sourceskyboxer/components/Component.hx:140: lines 140-143 : Field set_x is declared 'override' but doesn't override any field net/sourceskyboxer/components/Component.hx:148: lines 148-151 : Field set_y is declared 'override' but doesn't override any field Build halted with errors.