Created
February 8, 2012 19:17
-
-
Save zachwlewis/1772431 to your computer and use it in GitHub Desktop.
An attempt to create a reusable, design-based Flash UI boilerplate.
This file contains hidden or 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
| /** | |
| * @author Zachary Weston Lewis | |
| */ | |
| class Main extends MovieClip | |
| { | |
| public function Main(target:Object) | |
| { | |
| target.__proto__ = this.__proto__; | |
| target.__constructor__ = PlayerHUD; | |
| this = Main(target); | |
| trace("Main::constructor"); | |
| var app:PlayerHUD = PlayerHUD(attachMovie(PlayerHUD.id, "hud", 1)); | |
| } | |
| public static function main():Void | |
| { | |
| // Assimilate _root. | |
| var test:Main = new Main(_root); | |
| } | |
| } |
This file contains hidden or 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
| /** | |
| * @author Zachary Weston Lewis | |
| */ | |
| class PlayerHUD extends MovieClip | |
| { | |
| public static var id:String = (id = "__Packages.PlayerHUD") + (Object.registerClass(id, PlayerHUD)?"":""); | |
| public var HPBar:ValueBar; | |
| public var MPBar:ValueBar; | |
| public function PlayerHUD(target:Object) | |
| { | |
| trace("PlayerHUD::constructor"); | |
| trace(id); // > __Packages.PlayerHUD | |
| } | |
| public function onLoad():Void | |
| { | |
| trace("PlayerHUD::onLoad"); | |
| HPBar.setMax(100); | |
| for (var name:String in _root) | |
| { | |
| trace(name); | |
| /* This loop returns: | |
| * > __constructor__ | |
| * > $version | |
| * > hud | |
| * > MPBar | |
| * > HPBar | |
| */ | |
| } | |
| } | |
| } |
This file contains hidden or 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
| /** | |
| * @author Zachary Weston Lewis | |
| */ | |
| class ValueBar extends MovieClip | |
| { | |
| public var _bar:MovieClip; | |
| public var _label:TextField; | |
| private var _maxValue:Number; | |
| private var _currentValue:Number; | |
| private var BAR_WIDTH:Number = 200; | |
| public function ValueBar() | |
| { | |
| _maxValue = 1; | |
| _currentValue = 1; | |
| trace("ValueBar created."); | |
| updateLabel(); | |
| } | |
| public function setMax(value:Number):Void | |
| { | |
| _maxValue = value; | |
| draw(); | |
| } | |
| public function setValue(value:Number):Void | |
| { | |
| trace("Setting value to " + value); | |
| _currentValue = value; | |
| if (_currentValue > _maxValue) { _maxValue = value; } | |
| draw(); | |
| } | |
| private function draw():Void | |
| { | |
| updateBar(); | |
| updateLabel(); | |
| } | |
| private function updateBar():Void | |
| { | |
| _bar._xscale = (_currentValue / _maxValue); | |
| } | |
| private function updateLabel():Void | |
| { | |
| _label.text = _currentValue + "/" + _maxValue; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment