GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Github flash badge
Homepage: http://spinach.andascarygoat.com/tags/badjo
Clone URL: git://github.com/zmack/badjo.git
zmack (author)
Sun May 04 08:53:55 -0700 2008
commit  74d19885efaac6594492e3a96899075be008da81
tree    7433cbc2e23c5ac74a1880b291e5926aaf808706
parent  684dbc312be55e83d39966db83a793be04bbf1e0
badjo / src / ProjectList.as
100644 196 lines (155 sloc) 5.633 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package {
  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.text.StyleSheet;
  import flash.events.Event;
  import flash.events.MouseEvent;
  
  public class ProjectList extends Sprite {
    public const AVATAR_SIZE:uint = 40;
 
    public var backgroundColor:uint;
    public var listWidth:uint;
    public var listHeight:uint;
    public var lateralPadding:uint = 5;
    public var bottomPadding:uint = 5;
    
    private var _items:Array;
    private var _headerText:TextField;
    private var _mask:Sprite;
    private var _container:Sprite;
    private var _controls:Sprite;
    private var _buttonSpacing:uint;
    private var _maximum_y:uint;
 
    public function ProjectList(options:Object) {
      this.listWidth = options.width;
      this.listHeight = options.height;
      this._buttonSpacing = 5;
      this._maximum_y = 0;
      this.backgroundColor = 0x00FFD0;
      this._items = new Array();
 
      this._controls = this.createScroll();
      this._mask = this.createMask();
      this._container = new Sprite();
      addChild(this._mask);
      addChild(this._container);
      addChild(this._controls);
      this._container.mask = this._mask;
    }
    
    private function drawBackground():void {
      this.graphics.clear();
      this.graphics.beginFill(this.backgroundColor, 0.4);
      //this.graphics.lineStyle(2, 0x000000);
      this.graphics.drawRoundRect(0, 0, this.listWidth, this.listHeight, 15, 15);
    }
 
    public function redraw():void {
      this._maximum_y = 0;
      this._items.forEach( function(item:PickleButton, index:uint, arr:Array):void {
        this.positionButton(item);
        this._maximum_y = item.y + item.itemHeight;
      }, this);
      this.drawBackground();
    }
 
    public function addButton(options:Object):PickleButton {
      options.width = this.listWidth - 2 * this.lateralPadding;
      var button:PickleButton = new PickleButton(options);
      button.parentItem = this;
      this._items.push(button);
      this._container.addChild(button)
      this.positionButton(button);
 
      this._maximum_y = button.y + button.itemHeight;
      button.x = this.lateralPadding;
 
      trace(button.y);
      this.drawBackground();
      return button;
    }
 
    public function setHeader(options:Object):void {
      this._headerText = this.createTextField();
      this._headerText.height = AVATAR_SIZE;
      addChild(options.image);
      addChild(this._headerText);
 
      this._headerText.htmlText = '<h1>' + options.text + '<h1>';
      this._headerText.x = AVATAR_SIZE + this.lateralPadding*2;
      this._headerText.y = this.bottomPadding;
      this._headerText.width = this.listWidth - AVATAR_SIZE - this.lateralPadding*2;
      this._container.y = AVATAR_SIZE + this.bottomPadding;
      this._maximum_y = 0;
      options.image.y = this.bottomPadding;
      options.image.x = this.lateralPadding;
    }
 
    private function positionButton(button:PickleButton):void {
      button.y = this._maximum_y + this._buttonSpacing;
    }
 
    private function createStyleSheet():StyleSheet {
      var style:StyleSheet = new StyleSheet();
 
      style.parseCSS('h1 { font-family: "Trebuchet MS"; font-size: 20px; color: #000000; background-color: #FF00FF; }');
      return style;
    }
 
    private function createTextField():TextField {
      var text:TextField = new TextField();
      
      text.styleSheet = this.createStyleSheet();
      text.selectable = false;
 
      return text;
    }
 
    private function createMask():Sprite {
      var mask:Sprite = new Sprite;
 
      mask.graphics.clear();
      mask.graphics.beginFill(0x000000);
      mask.graphics.drawRoundRect(this.lateralPadding, this.getHeaderHeight() + this.bottomPadding, this.getMaskWidth(), this.getMaskHeight(), 15, 15);
      return mask;
    }
 
    private function getHeaderHeight():uint {
      return AVATAR_SIZE + this.bottomPadding;
    }
 
    private function getMaskHeight():uint {
      return this.listHeight - AVATAR_SIZE - 3 * this.bottomPadding - this._controls.height;
    }
 
    private function getMaskWidth():uint {
      return this.listWidth - 2 * this.lateralPadding;
    }
 
    private function scrollUp(e:Event):void {
      this._container.y -= 5;
    }
 
    private function scrollDown(e:Event):void {
      this._container.y += 5;
    }
 
    private function createScroll():Sprite {
      var scrollControls:Sprite = new Sprite;
 
      var scrollUp:Sprite = this.createScrollUp();
      var scrollDown:Sprite = this.createScrollDown();
 
      scrollControls.addChild(scrollUp);
      scrollControls.addChild(scrollDown);
      scrollUp.x = 30;
      scrollDown.x = 60;
 
      scrollControls.y = this.listHeight - scrollControls.height;
 
      return scrollControls;
    }
 
    private function createScrollUp():Sprite {
      var s:Sprite = this.createButtonyThing();
 
      s.addEventListener(MouseEvent.MOUSE_DOWN, this.startScrollUp);
      return s;
    }
 
    private function createScrollDown():Sprite {
      var s:Sprite = this.createButtonyThing();
 
      s.addEventListener(MouseEvent.MOUSE_DOWN, this.startScrollDown);
      return s;
    }
 
    private function startScrollUp(e:Event):void {
      stage.addEventListener(MouseEvent.MOUSE_UP, this.stopScroll);
      this.addEventListener(Event.ENTER_FRAME, this.scrollUp);
    }
 
    private function startScrollDown(e:Event):void {
      stage.addEventListener(MouseEvent.MOUSE_UP, this.stopScroll);
      this.addEventListener(Event.ENTER_FRAME, this.scrollDown);
    }
 
    private function stopScroll(e:Event):void {
      this.removeEventListener(Event.ENTER_FRAME, this.scrollUp);
      this.removeEventListener(Event.ENTER_FRAME, this.scrollDown);
      stage.removeEventListener(MouseEvent.MOUSE_UP, this.stopScroll);
    }
 
    private function createButtonyThing():Sprite {
      var s:Sprite = new Sprite();
 
      s.graphics.clear();
      s.graphics.beginFill(0xFFFFFF);
      s.graphics.drawRoundRect(0, 0, 15, 15, 15, 15);
 
      return s;
    }
  }
}