0
import flash.text.StyleSheet;
0
public class PickleButton extends Sprite {
0
+ public static const NORMAL_COLOR:uint = 0xFF00FF;
0
+ public static const SELECTED_COLOR:uint = 0x0F00F0;
0
public var text:String;
0
public var itemWidth:Number;
0
public var itemHeight:Number;
0
public var padding:Number;
0
+ public var parentItem:Object;
0
+ private var _backgroundColor:uint;
0
private var _image:Sprite;
0
private var _textField:TextField;
0
private var _style:StyleSheet;
0
+ private var _resizeHeight:uint;
0
public function PickleButton(options:Object) {
0
this.itemWidth = options.width || 200;
0
this.padding = options.padding || 5;
0
+ this._backgroundColor = PickleButton.NORMAL_COLOR;
0
this._image = options.image || new Sprite();
0
this._textField = this.createTextField();
0
this._textField.htmlText = '<p>' + (options.text || 'No text specified') + '</p>';
0
public function drawBackground(color:uint = 0xFF00FF):void {
0
+ color = this._backgroundColor;
0
this.graphics.beginFill(color, 0.4);
0
this.graphics.drawRoundRect(0, 0, this.itemWidth, this.itemHeight, 15, 15);
0
private function addEvents():void {
0
this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
0
this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
0
+ this.addEventListener(MouseEvent.CLICK, onClick);
0
private function onMouseOver(e:MouseEvent):void {
0
- this.drawBackground(0x0F00F0);
0
+ this._backgroundColor = PickleButton.SELECTED_COLOR;
0
+ this.drawBackground();
0
private function onMouseOut(e:MouseEvent):void {
0
+ trace("And we're out");
0
+ this._backgroundColor = PickleButton.NORMAL_COLOR;
0
+ private function onClick(e:MouseEvent):void {
0
+ if ( this.itemHeight == 50 ) {
0
private function createTextField():TextField {
0
var text:TextField = new TextField();
0
+ private function redraw():void {
0
+ this.drawBackground();
0
+ private function resizeTo(height:uint = 0):void {
0
+ var item:PickleButton = this;
0
+ height ||= this.getBaseHeight();
0
+ this._resizeHeight = height;
0
+ if ( !this.hasEventListener(Event.ENTER_FRAME) ) {
0
+ this.addEventListener(Event.ENTER_FRAME, this.resizer);
0
+ trace("Added listener");
0
+ private function resizer(e:Event):void {
0
+ if ( this.itemHeight != this._resizeHeight ) {
0
+ this.itemHeight += ( (itemHeight < this._resizeHeight)? 2 : -2 );
0
+ this.drawBackground();
0
+ (this.parentItem as ProjectList).redraw();
0
+ this.removeEventListener(Event.ENTER_FRAME, this.resizer);
0
+ trace("Removed listener");
0
private function resizeComponents():void {
0
- this.itemHeight = this.
_image.height + this.padding * 2;
0
+ this.itemHeight = this.
getBaseHeight();
0
this._textField.x = this._image.width + this.padding;
0
this._textField.width = this.itemWidth - this._image.width - this.padding;
0
this._textField.height = this.itemHeight - this.padding * 1;
0
this._image.x = this.padding;
0
this._image.y = this.padding;
0
+ private function getBaseHeight() {
0
+ return this._image.height + this.padding * 2;
0
private function createStyleSheet():StyleSheet {
Comments
No one has commented yet.