source: branches/captions/src/com/longtailvideo/plugins/captions/graphics/Selector.as @ 1706

Revision 1706, 3.1 KB checked in by jeroen, 2 years ago (diff)

some incremental work on multilanguage captions - mostly structuring the app

  • Property svn:executable set to *
Line 
1package com.longtailvideo.plugins.captions.graphics {
2
3
4    import flash.display.*;
5
6
7    /** Component that renders a select box. **/
8    public class Selector extends Sprite {
9
10
11        /** Compiles of the default graphics. **/
12        [Embed(source="../../../../../../assets/downDisabled.png")]
13        private const DownDisabled:Class;
14        [Embed(source="../../../../../../assets/downOut.png")]
15        private const DownOut:Class;
16        [Embed(source="../../../../../../assets/downOver.png")]
17        private const DownOver:Class;
18        [Embed(source="../../../../../../assets/divider.png")]
19        private const Divider:Class;
20        [Embed(source="../../../../../../assets/upDisabled.png")]
21        private const UpDisabled:Class;
22        [Embed(source="../../../../../../assets/upOut.png")]
23        private const UpOut:Class;
24        [Embed(source="../../../../../../assets/upOver.png")]
25        private const UpOver:Class;
26
27
28        /** currently active option. **/
29        private var _active:Number;
30        /** Function to call when a selection is made. **/
31        private var _callback:Function;
32        /** Reference to the down clip. **/
33        private var _down:Sprite;
34        /** List with options from the selector. **/
35        private var _options:Array;
36        /** Reference to the up clip. **/
37        private var _up:Sprite;
38
39
40        /** Constructor. **/
41        public function Selector(callback:Function) {
42            _callback = callback;
43            _down = new Sprite();
44            _down.addChild(new DownDisabled());
45            _up = new Sprite();
46            _up.addChild(new UpDisabled());
47        };
48
49
50        /** Button was clicked. **/
51        private function _buttonHandler(index:Number):void {
52            _callback(index);
53        };
54
55
56        /** Populate the selector with a number of items. **/
57        public function populate(options:Array):void {
58            var offset:Number;
59            var button:SelectorButton;
60            var divider:DisplayObject;
61            _options = options;
62            addChild(_up);
63            _up.y = 0;
64            offset = _up.height;
65            for(var i:Number = 0; i < _options.length+1; i++) {
66                divider = new Divider();
67                addChild(divider);
68                divider.y = offset;
69                offset += divider.height;
70                if(i < _options.length) {
71                    button = new SelectorButton(_buttonHandler,i,_options[i].label);
72                    addChild(button);
73                    button.y = offset;
74                    offset += button.height;
75                }
76            }
77            addChild(_down);
78            _down.y = offset;
79        };
80
81
82        /** Set a certain selector. **/
83        public function select(label:String):void {
84            var index:Number = -1;
85            // Search for the correct index.
86            for(var i:Number = 0; i < _options.length; i++) {
87                if(_options[i] == label) {
88                    index  = i;
89                    break;
90                }
91            }
92            // If found, change the selector
93            if(index > -1) {
94           
95            }
96        };
97
98
99};
100
101
102}
Note: See TracBrowser for help on using the repository browser.