Created
June 4, 2014 06:38
-
-
Save k0t0vich/67c762bf9bca2d2df7f5 to your computer and use it in GitHub Desktop.
without super/this etc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package components { | |
/** | |
* | |
* @author Dimarik | |
* @version 1.0 | |
* @langversion 3.0 | |
* @playerversion Flash 10 | |
* @playerversion AIR 1.5 | |
* | |
* @keyword button, togglebutton | |
*/ | |
public class ToggleButton extends Sprite { | |
public function ToggleButton() { | |
super(); | |
addEventListener(MouseEvent.CLICK, handler_click); | |
// Скины не должны быть источником событий. Только сам компонент. | |
mouseChildren = false; | |
} | |
//------------------------------------------------------------------------- | |
// | |
// Properties | |
// | |
//------------------------------------------------------------------------- | |
private var _selected: Boolean; | |
/** | |
* Contains <code>true</code> if the button is in the down state, | |
* and <code>false</code> if it is in the up state. | |
*/ | |
public function get selected():Boolean { | |
return _selected; | |
} | |
public function set selected(value:Boolean):void { | |
if (_selected === value) | |
return; | |
_selected = value; | |
validateState(); | |
} | |
private var _upSkin: DisplayObject; | |
public function set upSkin(value:DisplayObject):void { | |
if (_upSkin === value) | |
return; | |
if (_upSkin && _upSkin.parent) | |
removeChild(_upSkin); | |
_upSkun = value; | |
validateState(); | |
} | |
public function get upSkin():DisplayObject { | |
return _upSkin; | |
} | |
private var _upAndSelectedSkin: DisplayObject; | |
public function set upAndSelectedSkin(value:DisplayObject):void { | |
if (_upAndSelectedSkin === value) | |
return; | |
if (_upAndSelectedSkin && _upAndSelectedSkin.parent) | |
removeChild(_upAndSelectedSkin); | |
_upSkun = value; | |
validateState(); | |
} | |
public function get upAndSelectedSkin():DisplayObject { | |
return _upSkin; | |
} | |
//------------------------------------------------------------------------- | |
// | |
// Private methods | |
// | |
//------------------------------------------------------------------------- | |
private function validateState():void { | |
if (_selected) { | |
if (_upSkin && _upSkin.parent) { | |
removeChild(_upSkin); | |
} | |
if (_upAndSelectedSkin) | |
addChild(_upAndSelectedSkin); | |
} else { | |
if (_upAndSelectedSkin && _upAndSelectedSkin.parent) { | |
removeChild(_upAndSelectedSkin); | |
} | |
if (_upSkin) | |
addChild(_upSkin); | |
} | |
} | |
//------------------------------------------------------------------------- | |
// | |
// Event handlers | |
// | |
//------------------------------------------------------------------------- | |
protected function handler_click(event:MouseEvent):void { | |
selected = !selected; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment