From 38ac2a0de40e8c1542b21d797237db25a8f0afa7 Mon Sep 17 00:00:00 2001 From: Andrei Bocan Date: Sat, 26 Apr 2008 15:32:33 +0300 Subject: [PATCH] Projects -> PickleButtons --- src/PickleButton.as | 83 +++++++++++++++++++++++++++++++++++++++++++++ src/Project.as | 54 ----------------------------- 2 files changed, 83 insertions(+), 54 deletions(-) create mode 100644 src/PickleButton.as delete mode 100644 src/Project.as diff --git a/src/PickleButton.as b/src/PickleButton.as new file mode 100644 index 0000000..2439507 --- /dev/null +++ b/src/PickleButton.as @@ -0,0 +1,83 @@ +package { + import flash.events.Event; + import flash.events.MouseEvent; + import flash.display.Sprite; + import flash.text.TextField; + import flash.text.StyleSheet; + + public class PickleButton extends Sprite { + public var text:String; + public var itemWidth:Number; + public var itemHeight:Number; + public var padding:Number; + + private var _image:Sprite; + private var _textField:TextField; + private var _style:StyleSheet; + + public function Project(options:Object) { + this.itemWidth = options.width || 200; + this.padding = options.padding || 5; + + this._image = options.image || new Sprite(); + this._textField = this.createTextField(); + this._textField.htmlText = '

' + (options.text || 'No text specified') + '

'; + + this.resizeComponents(); + this.drawBackground(); + addChild(this._textField); + addChild(this._image); + this.addEvents(); + } + + public function drawBackground(color:uint = 0xFF00FF):void { + this.graphics.clear(); + this.graphics.beginFill(color, 0.4); + this.graphics.drawRoundRect(0, 0, this.itemWidth, this.itemHeight, 15, 15); + } + + private function addEvents():void { + this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); + this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); + } + + private function onMouseOver(e:MouseEvent):void { + this.drawBackground(0x0F00F0); + } + + private function onMouseOut(e:MouseEvent):void { + this.drawBackground(); + } + + private function createTextField():TextField { + var text:TextField = new TextField(); + + text.y = this.padding; + text.styleSheet = this.createStyleSheet(); + text.multiline = true; + text.wordWrap = true; + text.selectable = false; + + return text; + } + + private function resizeComponents():void { + this.itemHeight = this._image.height + this.padding * 2; + this._textField.x = this._image.width + this.padding; + this._textField.width = this.itemWidth - this._image.width - this.padding; + this._textField.height = this.itemHeight - this.padding * 2; + + this._image.x = this.padding; + this._image.y = this.padding; + } + + private function createStyleSheet():StyleSheet { + var style:StyleSheet = new StyleSheet(); + + style.parseCSS('p { font-family: "Trebuchet MS"; font-size: 11px; color: #000000; background-color: #FF00FF; }'); + + return style; + } + + } +} diff --git a/src/Project.as b/src/Project.as deleted file mode 100644 index c755254..0000000 --- a/src/Project.as +++ /dev/null @@ -1,54 +0,0 @@ -package { - import flash.display.Sprite; - import flash.text.TextField; - import flash.text.StyleSheet; - - public class Project extends Sprite { - public var text:String; - public var itemWidth:Number; - public var itemHeight:Number; - - private var _textField:TextField; - private var _style:StyleSheet; - - public function Project(options:Object) { - this.itemWidth = options.width || 200; - this.itemHeight = options.height || 40; - this._textField = this.createTextField(); - this._textField.htmlText = '

This is a little little bit of twit we do a swift

'; - - this.draw(); - addChild(this._textField); - } - - public function draw():void { - this.graphics.clear(); - this.graphics.beginFill(0xFF00FF, 0.4); - this.graphics.drawRoundRect(0, 0, this.itemWidth, this.itemHeight, 15, 15); - } - - private function createTextField():TextField { - var text:TextField = new TextField(); - - text.width = this.itemWidth - 50; - text.height = this.itemHeight - 10; - text.x = 40; - text.y = 5; - text.styleSheet = this.createStyleSheet(); - text.multiline = true; - text.wordWrap = true; - - return text; - } - - private function createStyleSheet():StyleSheet { - var style:StyleSheet = new StyleSheet(); - - style.parseCSS('p { font-family: "Trebuchet MS"; font-size: 10px; color: #000000; background-color: #FF00FF; }'); - trace(style.getStyle('p').color); - - return style; - } - - } -}