/**
* Copyright hemingway ( http://wonderfl.net/user/hemingway )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/AlyC
*/
package {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
[SWF(frameRate=60, width=465, height=465)]
public class Canvas extends Sprite {
private const STAGE_WIDTH:Number = 465;
private const STAGE_HEIGHT:Number = 465;
//Drawing
private var _drawCanvas:Bitmap;
private var _drawData:BitmapData;
private var _drawBuffer:Vector.<*>;
//Accordian
private const PANEL_BG:uint = 0x6BBFE5;
private const PANEL_FG:uint = 0x3C6A7F;
private var _panel:Panel;
private var _panelRect:Rectangle;
private var _panelColorA:ColorTransform;
private var _panelColorB:ColorTransform;
//AccordianButton
private const BUTTON_BG:uint = 0xE2F8FF;
private const BUTTON_FG:uint = 0xBBCED4;
private var _accButtonA:AccordianButton;
private var _accButtonARect:Rectangle;
private var _accButtonB:AccordianButton;
private var _accButtonBRect:Rectangle;
private var _accButtonColorA:ColorTransform;
private var _accButtonColorB:ColorTransform;
//Misc
private var _mouseDown:Boolean;
public function Canvas() {
//Drawing
this._drawData = new BitmapData(this.STAGE_WIDTH, this.STAGE_HEIGHT, false, 0);
this._drawCanvas = new Bitmap(this._drawData);
this._drawBuffer = new Vector.<*>(99, true);
//Panel
var $pW:Number = 256;
var $pH:Number = 320;
var $pX:Number = (this.STAGE_WIDTH/2-$pW/2);
var $pY:Number = (this.STAGE_HEIGHT/2-$pH/2);
this._panelColorA = new ColorTransform();
this._panelColorA.color = this.PANEL_BG;
this._panelColorB = new ColorTransform();
this._panelColorB.color = this.PANEL_FG;
this._panelRect = new Rectangle($pX, $pY, $pW, $pH);
//AccordianButton
var $baW:Number = $pW - 24;
var $baH:Number = 24;
var $baX:Number = $pX + 12;
var $baY:Number = $pY + 12;
this._accButtonColorA = new ColorTransform();
this._accButtonColorA.color = this.BUTTON_BG;
this._accButtonColorB = new ColorTransform();
this._accButtonColorB.color = this.BUTTON_FG;
this._accButtonARect = new Rectangle($baX, $baY, $baW, $baH);
this._accButtonBRect = new Rectangle();
this.addEventListener(Event.ADDED_TO_STAGE, this.addedToStageHandler);
}
private function addedToStageHandler($event:Event):void {
this.removeEventListener(Event.ADDED_TO_STAGE, this.addedToStageHandler);
this.addChild(this._drawCanvas);
this._panel = new Panel(this._panelRect, this._panelColorA, this._panelColorB);
this._accButtonA = new AccordianButton(this._accButtonARect, this._accButtonColorA, this._accButtonColorB, "label", this.addChildCallback);
this._drawBuffer[0] = this._panel;
this._drawBuffer[1] = this._accButtonA;
this.addEventListener(Event.ENTER_FRAME, this.enterFrameHandler);
}
private function mouseDownHandler($event:MouseEvent):void {
this.stage.focus = this._accButtonA;
}
private function mouseUpHandler($event:MouseEvent):void {
}
private function enterFrameHandler($event:Event):void {
for (var $:int = 0; $ < this._drawBuffer.length; $++) {
if (this._drawBuffer[$].draw) {
this._drawBuffer[$].draw = false;
this._drawData.colorTransform(this._drawBuffer[$].rectB, this._drawBuffer[$].colorB);
this._drawData.colorTransform(this._drawBuffer[$].rectA, this._drawBuffer[$].colorA);
}
}
}
public function addChildCallback($object:*):void {
this.addChild($object);
}
}
}
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.events.Event;
internal class Panel {
public var rectA:Rectangle;
public var rectB:Rectangle;
public var colorA:ColorTransform;
public var colorB:ColorTransform;
public var label:String;
public var draw:Boolean;
public function Panel($rect:Rectangle,
$colorA:ColorTransform,
$colorB:ColorTransform,
$label:String="Panel") {
this.rectA = $rect;
this.rectB = new Rectangle($rect.x-4, $rect.y-4, $rect.width+8, $rect.height+8);
this.colorA = $colorA;
this.colorB = $colorB;
this.label = $label;
this.draw = true;
}
public function get x() {
return this.rectB.x;
}
public function get y() {
return this.rectB.y;
}
public function get width() {
return this.rectB.width;
}
public function get height() {
return this.rectB.height;
}
public function set x($x:int):void {
this.rectA.x = $x;
}
}
internal class AccordianButton {
public var rectA:Rectangle;
public var rectB:Rectangle;
public var colorA:ColorTransform;
public var colorB:ColorTransform;
public var labelField:DataField;
public var label:String;
public var draw:Boolean;
public function AccordianButton($rect:Rectangle,
$colorA:ColorTransform,
$colorB:ColorTransform,
$label:String,
$childCallback:Function) {
this.rectA = $rect;
this.rectB = new Rectangle($rect.x-4, $rect.y-4, $rect.width+8, $rect.height+8);
this.colorA = $colorA;
this.colorB = $colorB;
this.label = $label;
this.draw = true;
this.labelField = new DataField($label, this.rectA.x+4, this.rectA.y+3);
this.addChild(this.labelField);
}
}
class DataField extends TextField
{
private var _x :Number;
private var _y :Number;
private var _font :String;
private var _data :String;
public function DataField($data:String = "", $x:Number = 4, $y:Number = 2, $font:String = "Consolas")
{
this._x = $x;
this._y = $y;
this._font = $font;
this._data = $data;
this.addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
}
private function addedToStageHandler($event:Event) :void
{
this.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
this.multiline = true;
this.autoSize = "left";
this.selectable = false;
this.mouseEnabled = false;
this.init();
}
private function init() :void
{
this.x = _x;
this.y = _y;
this.text = _data;
this.setTextFormat(new TextFormat(this.font, null, 0));
}
public function get font() :String
{ return this._font }
public function set font($font:String) :void
{ this._font = $font; this.setTextFormat(new TextFormat(this.font, null, 0)); }
public override function set text($data:String) :void
{ super.text = $data; this.setTextFormat(new TextFormat(this.font, null, 0)); }
}