public
Created

An attempt to create a reusable, design-based Flash UI boilerplate.

  • Download Gist
Main.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/**
* @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);
}
}
PlayerHUD.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/**
* @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
*/
}
}
}
ValueBar.as
ActionScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
/**
* @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;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.