forked from arpit/openpyro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleRepeater.as
More file actions
122 lines (96 loc) · 2.86 KB
/
SimpleRepeater.as
File metadata and controls
122 lines (96 loc) · 2.86 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
package{
import org.openPyro.core.UIContainer;
import org.openPyro.layout.VLayout;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class SimpleRepeater extends Sprite{
private var renderers:Array = []
public function SimpleRepeater(){
stage.scaleMode = "noScale"
stage.align = "TL";
var bttn:Sprite = new Sprite()
var gr:Graphics = bttn.graphics;
gr.lineStyle(1, 0x333333)
gr.beginFill(0xcccccc)
gr.drawRect(0,0,100,40);
gr.endFill();
bttn.addEventListener(MouseEvent.MOUSE_DOWN, onBttnClick);
addChild(bttn);
bttn.x = 500
bttn.y = 100;
var container:UIContainer = new UIContainer();
container.width = 300;
container.height = 600;
container.layout = new VLayout();
addChild(container);
for(var i:uint=0; i<5; i++){
var renderer:Renderer = new Renderer();
renderer.width = 300
container.addChild(renderer);
renderers.push(renderer);
}
var r:Renderer = renderers[0]
r.addEventListener(Event.RESIZE, onResize);
}
private function onResize(event:Event):void{
trace('renderer got resized to '+event.target.height);
}
private var i:uint = 0
private var stringList:Array = ["Lorem ipsum dolor sit amet, consectetuer " +
"adipiscing elit. Etiam lectus risus, semper varius," +
" imperdiet quis, sollicitudin nec, est. Cras in ipsum." +
" Mauris eu metus quis lorem aliquet blandit. Aliquam ",
'hello World']
public function onBttnClick(event:MouseEvent):void{
for each(var r:Renderer in renderers){
r.label = stringList[i]
i++;
if(i == stringList.length){
i=0;
}
}
}
}
}
import flash.display.Sprite;
import flash.display.Graphics;
import org.openPyro.core.UIControl;
import flash.text.TextField;
import net.comcast.logging.Logger;
import net.comcast.logging.consoles.TraceConsole;
internal class Renderer extends UIControl{
private var txt:TextField;
public function Renderer(){
//Logger.addConsole(new TraceConsole());
txt = new TextField()
txt.border=true;
addChild(txt);
txt.autoSize = "left";
txt.wordWrap=true;
}
public function set label(s:String):void{
this.txt.text = s;
this.invalidateSize()
}
override public function measure():void{
super.measure()
this.measuredHeight = this.txt.height+20;
//trace('[ ROOT set height ]'+_measuredHeight)
}
override public function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
trace(this, " -> updateDisplayList ")
super.updateDisplayList(unscaledWidth, unscaledHeight);
txt.width = unscaledWidth-20
txt.x = 10
txt.y = 10
txt.height = 20
var gr:Graphics = this.graphics;
gr.clear()
gr.lineStyle(1, 0x333333)
gr.beginFill(0xcccccc)
gr.drawRect(0,0,unscaledWidth,unscaledHeight);
gr.endFill();
}
}