Rev 73 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 73 | Rev 641 | ||
|---|---|---|---|
| 1 | import mx.transitions.Tween; |
1 | import mx.transitions.Tween; |
| 2 | 2 | ||
| 3 | class MenuDescObj { |
3 | class MenuDescObj { |
| 4 | 4 | ||
| 5 | private var menuItem:MovieClip; |
5 | private var menuItem:MovieClip; |
| 6 | private var menuText:TextField; |
6 | private var menuText:TextField; |
| 7 | private var menuFont:TextFormat; |
7 | private var menuFont:TextFormat; |
| 8 | 8 | ||
| 9 | private var menuVisible:Boolean = false; |
9 | private var menuVisible:Boolean = false; |
| 10 | private var inUse:Boolean = false; |
10 | private var inUse:Boolean = false; |
| 11 | 11 | ||
| 12 | private var textWidth:Number; |
12 | private var textWidth:Number; |
| 13 | private var fontSize:Number; |
13 | private var fontSize:Number; |
| 14 | private var unitHeight:Number; |
14 | private var unitHeight:Number; |
| 15 | private var maxHeight:Number; |
15 | private var maxHeight:Number; |
| 16 | 16 | ||
| 17 | private var scrollTime:Number; |
17 | private var scrollTime:Number; |
| 18 | 18 | ||
| 19 | function MenuDescObj (mainScene:MovieClip, font:TextFormat, scrollTime:Number, left:Number, width:Number, top:Number, maxHeight:Number, unitHeight:Number) { |
19 | function MenuDescObj (mainScene:MovieClip, font:TextFormat, scrollTime:Number, left:Number, width:Number, top:Number, maxHeight:Number, unitHeight:Number) { |
| 20 | this.scrollTime = scrollTime; |
20 | this.scrollTime = scrollTime; |
| 21 | menuItem = mainScene.createEmptyMovieClip("menuItem", mainScene.getNextHighestDepth()); |
21 | menuItem = mainScene.createEmptyMovieClip("menuItem", mainScene.getNextHighestDepth()); |
| 22 | menuItem._x = left; |
22 | menuItem._x = left; |
| 23 | menuItem._y = top; |
23 | menuItem._y = top; |
| 24 | menuFont = font; |
24 | menuFont = font; |
| 25 | this.unitHeight = unitHeight; |
25 | this.unitHeight = unitHeight; |
| 26 | this.maxHeight = maxHeight; |
26 | this.maxHeight = maxHeight; |
| 27 | menuText = menuItem.createTextField("menuText", 1, 0, 0, 0, 10); |
27 | menuText = menuItem.createTextField("menuText", 1, 0, 0, 0, 10); |
| 28 | menuText.embedFonts = true; |
28 | menuText.embedFonts = true; |
| 29 | 29 | ||
| 30 | //size the textfield, strange way |
30 | //size the textfield, strange way |
| 31 | menuText.text = "-"; |
31 | menuText.text = "-"; |
| 32 | menuText.setTextFormat(menuFont); |
32 | menuText.setTextFormat(menuFont); |
| 33 | menuText.autoSize = "left"; |
33 | menuText.autoSize = "left"; |
| 34 | fontSize = menuText._height; |
34 | fontSize = menuText._height; |
| 35 | menuText.autoSize = "none"; |
35 | menuText.autoSize = "none"; |
| 36 | 36 | ||
| 37 | menuText._width = width*fontSize / unitHeight * 1.2; //(1.2 to fit more text) |
37 | menuText._width = width*fontSize / unitHeight * 1.2; //(1.2 to fit more text) |
| 38 | menuItem._width = width; |
38 | menuItem._width = width; |
| 39 | 39 | ||
| 40 | menuText.multiline = true; |
40 | menuText.multiline = true; |
| 41 | //menuText.html = true; |
41 | //menuText.html = true; |
| 42 | menuText.wordWrap = true; |
42 | menuText.wordWrap = true; |
| 43 | menuText.selectable = false; |
43 | menuText.selectable = false; |
| 44 | //menuText.textColor = 0xFF0000; |
44 | //menuText.textColor = 0xFF0000; |
| 45 | menuText.type = "dynamic"; |
45 | menuText.type = "dynamic"; |
| 46 | menuItem._visible = false; |
46 | menuItem._visible = false; |
| 47 | 47 | ||
| 48 | menuText._height = fontSize; |
48 | menuText._height = fontSize; |
| 49 | menuItem._height = unitHeight; |
49 | menuItem._height = unitHeight; |
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | } //end constructor |
52 | } //end constructor |
| 53 | 53 | ||
| 54 | public function update(text:String) { |
54 | public function update(text:String) { |
| 55 | //rutinen skall skrivas om, då objektet laddas skall man testa raderna vs height |
55 | //rutinen skall skrivas om, då objektet laddas skall man testa raderna vs height |
| 56 | //så det görs EN gång |
56 | //så det görs EN gång |
| 57 | 57 | ||
| 58 | menuText.text = text; |
58 | menuText.text = text; |
| 59 | //menuText.htmlText |
59 | //menuText.htmlText |
| 60 | menuText.setTextFormat(menuFont); |
60 | menuText.setTextFormat(menuFont); |
| 61 | menuText._height = fontSize; |
61 | menuText._height = fontSize; |
| 62 | menuItem._height = unitHeight; |
62 | menuItem._height = unitHeight; |
| 63 | 63 | ||
| 64 | //trace("bottom: " + menuText.bottomScroll + " max: " + menuText.maxscroll); |
64 | //trace("bottom: " + menuText.bottomScroll + " max: " + menuText.maxscroll); |
| 65 | if (text.length > 0) { |
65 | if (text.length > 0) { |
| 66 | 66 | ||
| 67 | for (var i:Number = fontSize; true; i = i+fontSize/5) { |
67 | for (var i:Number = fontSize; true; i = i+fontSize/5) { |
| 68 | menuText._height = i*fontSize/unitHeight; |
68 | menuText._height = i*fontSize/unitHeight; |
| 69 | menuItem._height = i; |
69 | menuItem._height = i; |
| 70 | menuText.text = text; |
70 | menuText.text = text; |
| 71 | menuText.setTextFormat(menuFont); |
71 | menuText.setTextFormat(menuFont); |
| 72 | if (menuText.maxscroll == 1) { |
72 | if (menuText.maxscroll == 1) { |
| 73 | break; |
73 | break; |
| 74 | } |
74 | } |
| 75 | if (menuItem._height > maxHeight) { |
75 | if (menuItem._height > maxHeight) { |
| 76 | menuText._height = (i-fontSize/5)*fontSize/unitHeight; |
76 | menuText._height = (i-fontSize/5)*fontSize/unitHeight; |
| 77 | menuItem._height = (i-fontSize/5); |
77 | menuItem._height = (i-fontSize/5); |
| 78 | 78 | ||
| 79 | break; |
79 | break; |
| 80 | } |
80 | } |
| 81 | 81 | ||
| 82 | //TODO: ta bort denna! |
82 | //TODO: ta bort denna! |
| 83 | if (i > 500) { |
83 | if (i > 500) { |
| 84 | trace(menuItem._height + " " + maxHeight); |
84 | trace(menuItem._height + " " + maxHeight); |
| 85 | break; |
85 | break; |
| 86 | } |
86 | } |
| 87 | //trace(menuText.maxscroll + " " + menuText.scroll + " " + menuText.bottomScroll); |
87 | //trace(menuText.maxscroll + " " + menuText.scroll + " " + menuText.bottomScroll); |
| 88 | //trace(menuText.bottomScroll + " fontsize: " + fontSize + " i: " + i + " menutext-height: " + menuText._height); |
88 | //trace(menuText.bottomScroll + " fontsize: " + fontSize + " i: " + i + " menutext-height: " + menuText._height); |
| 89 | } |
89 | } |
| 90 | } else { |
90 | } else { |
| 91 | menuItem._height = 0; |
91 | menuItem._height = 0; |
| 92 | } |
92 | } |
| 93 | 93 | ||
| 94 | } |
94 | } |
| 95 | 95 | ||
| 96 | //public function getSize |
96 | //public function getSize |
| 97 | 97 | ||
| 98 | public function appear() { |
98 | public function appear() { |
| 99 | inUse = true; |
99 | inUse = true; |
| 100 | menuItem._visible = (menuVisible && inUse); |
100 | menuItem._visible = (menuVisible && inUse); |
| 101 | var test:Tween = new Tween(menuText, "_alpha", null, 5, 100, scrollTime, true); |
101 | var test:Tween = new Tween(menuText, "_alpha", null, 5, 100, scrollTime, true); |
| 102 | 102 | ||
| 103 | } |
103 | } |
| 104 | 104 | ||
| 105 | public function hide() { |
105 | public function hide() { |
| 106 | inUse = false; |
106 | inUse = false; |
| 107 | menuItem._visible = (menuVisible && inUse); |
107 | menuItem._visible = (menuVisible && inUse); |
| 108 | //var test:Tween = new Tween(menuText, "_alpha", null, 5, 100, 1, true); |
108 | //var test:Tween = new Tween(menuText, "_alpha", null, 5, 100, 1, true); |
| 109 | 109 | ||
| 110 | } |
110 | } |
| 111 | 111 | ||
| 112 | public function setText(text:String) { |
112 | public function setText(text:String) { |
| 113 | menuText.text = text; |
113 | menuText.text = text; |
| 114 | menuText.setTextFormat(menuFont); |
114 | menuText.setTextFormat(menuFont); |
| 115 | } |
115 | } |
| 116 | 116 | ||
| 117 | public function visible(isVisible:Boolean) { |
117 | public function visible(isVisible:Boolean) { |
| 118 | menuVisible = isVisible; |
118 | menuVisible = isVisible; |
| 119 | menuItem._visible = (menuVisible && inUse); |
119 | menuItem._visible = (menuVisible && inUse); |
| 120 | } |
120 | } |
| 121 | 121 | ||
| 122 | public function getTop():Number { |
122 | public function getTop():Number { |
| 123 | return menuItem._y; |
123 | return menuItem._y; |
| 124 | } |
124 | } |
| 125 | public function getBottom():Number { |
125 | public function getBottom():Number { |
| 126 | return menuItem._y + menuItem._height; |
126 | return menuItem._y + menuItem._height; |
| 127 | } |
127 | } |
| 128 | /*public function setTop(top:Number) { |
128 | /*public function setTop(top:Number) { |
| 129 | //animera senare? |
129 | //animera senare? |
| 130 | //menuItem._visible = (menuVisible && inUse); |
130 | //menuItem._visible = (menuVisible && inUse); |
| 131 | menuItem._y = top; |
131 | menuItem._y = top; |
| 132 | }*/ |
132 | }*/ |
| 133 | public function setHeight(height:Number) { |
133 | public function setHeight(height:Number) { |
| 134 | //animera senare? |
134 | //animera senare? |
| 135 | //menuItem._visible = (menuVisible && inUse); |
135 | //menuItem._visible = (menuVisible && inUse); |
| 136 | menuItem._height = height; |
136 | menuItem._height = height; |
| 137 | } |
137 | } |
| 138 | 138 | ||
| 139 | } |
139 | } |