| 1 | package com.longtailvideo.plugins.captions { |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | import flash.display.*; |
|---|
| 5 | import flash.events.*; |
|---|
| 6 | import flash.text.*; |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | /** A single selector button. **/ |
|---|
| 10 | public class SelectorButton extends Sprite { |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | /** Embeds of the default graphics. **/ |
|---|
| 14 | [Embed(source="../../../../../assets/divider.png")] |
|---|
| 15 | private const ButtonBack:Class; |
|---|
| 16 | [Embed(source="../../../../../assets/active.png")] |
|---|
| 17 | private const ActiveIcon:Class; |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | /** The icon that indicates the item is active. **/ |
|---|
| 21 | private var _active:DisplayObject; |
|---|
| 22 | /** Background of the button. **/ |
|---|
| 23 | private var _back:DisplayObject; |
|---|
| 24 | /** Textfield of the button. **/ |
|---|
| 25 | private var _field:TextField; |
|---|
| 26 | /** Label of the textfield. **/ |
|---|
| 27 | private var _label:String; |
|---|
| 28 | /** Formatting of the textfield. **/ |
|---|
| 29 | private var _format:TextFormat; |
|---|
| 30 | /** Handler to call when the button is clicked. **/ |
|---|
| 31 | private var _handler:Function; |
|---|
| 32 | /** Index of the button. **/ |
|---|
| 33 | private var _index:Number; |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | /** Constructor. **/ |
|---|
| 37 | public function SelectorButton(handler:Function,index:Number,label:String) { |
|---|
| 38 | _handler = handler; |
|---|
| 39 | _index = index; |
|---|
| 40 | _label = label; |
|---|
| 41 | _back = new ButtonBack(); |
|---|
| 42 | _back.height = 30; |
|---|
| 43 | _back.alpha = 0; |
|---|
| 44 | addChild(_back); |
|---|
| 45 | _field = new TextField(); |
|---|
| 46 | addChild(_field); |
|---|
| 47 | // Create the text formatting. |
|---|
| 48 | _format = new TextFormat(); |
|---|
| 49 | _format.color = 0xFFFFFF; |
|---|
| 50 | _format.size = 12; |
|---|
| 51 | _format.align = TextFormatAlign.LEFT; |
|---|
| 52 | _format.font = "_sans"; |
|---|
| 53 | _field.defaultTextFormat = _format; |
|---|
| 54 | // Set other textfield props. |
|---|
| 55 | _field.selectable = false; |
|---|
| 56 | _field.height = 20; |
|---|
| 57 | _field.x = 80; |
|---|
| 58 | _field.width = 160; |
|---|
| 59 | _field.y = _back.height/2 - 9; |
|---|
| 60 | _field.htmlText = label; |
|---|
| 61 | buttonMode = true; |
|---|
| 62 | mouseChildren = false; |
|---|
| 63 | _active = new ActiveIcon(); |
|---|
| 64 | _active.x = 65; |
|---|
| 65 | _active.y = 12; |
|---|
| 66 | _active.visible = false; |
|---|
| 67 | addChild(_active); |
|---|
| 68 | addEventListener(MouseEvent.CLICK,_clickHandler); |
|---|
| 69 | addEventListener(MouseEvent.MOUSE_OUT,_outHandler); |
|---|
| 70 | addEventListener(MouseEvent.MOUSE_OVER,_overHandler); |
|---|
| 71 | }; |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | /** (de)activate the button. **/ |
|---|
| 75 | public function activate(state:Boolean):void { |
|---|
| 76 | if(state) { |
|---|
| 77 | _field.htmlText = '<b>'+_label+'</b>'; |
|---|
| 78 | _active.visible = true; |
|---|
| 79 | } else { |
|---|
| 80 | _field.htmlText = _label; |
|---|
| 81 | _active.visible = false; |
|---|
| 82 | } |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | /** Register the click. **/ |
|---|
| 87 | private function _clickHandler(event:MouseEvent):void { |
|---|
| 88 | _handler(_index); |
|---|
| 89 | }; |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | /** Fade the back on rollover. **/ |
|---|
| 93 | private function _outHandler(event:MouseEvent):void { |
|---|
| 94 | _back.alpha = 0; |
|---|
| 95 | }; |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | /** Fade the back on rollover. **/ |
|---|
| 99 | private function _overHandler(event:MouseEvent):void { |
|---|
| 100 | _back.alpha = 0.3; |
|---|
| 101 | }; |
|---|
| 102 | |
|---|
| 103 | }; |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | } |
|---|