Changeset 21457 for lang/actionscript
- Timestamp:
- 10/17/08 01:48:52 (3 months ago)
- Location:
- lang/actionscript/PagingChunk/trunk
- Files:
-
- 3 modified
-
PagingChunk.as3proj (modified) (2 diffs)
-
genms/controls/PagingChunk.mxml (modified) (16 diffs)
-
test.mxml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/actionscript/PagingChunk/trunk/PagingChunk.as3proj
r4489 r21457 52 52 <!-- example: <element path="..." /> --> 53 53 </rslPaths> 54 <!-- Intrinsic Libraries --> 55 <intrinsics> 56 <!-- example: <element path="..." /> --> 57 </intrinsics> 54 58 <!-- Assets to embed into the output SWF --> 55 59 <library> … … 71 75 <options> 72 76 <option showHiddenPaths="False" /> 73 <option testMovie="New Tab" />77 <option testMovie="NewWindow" /> 74 78 </options> 75 79 </project> -
lang/actionscript/PagingChunk/trunk/genms/controls/PagingChunk.mxml
r4489 r21457 15 15 <mx:Script> 16 16 <![CDATA[ 17 import flash.display.SimpleButton; 17 18 import flash.events.Event; 18 19 import genms.controls.PagingChunkEvent; … … 35 36 36 37 public function set pageNum(n:int):void { 37 unmarkCurrentPage(); 38 38 if (n <= 0) { 39 return; 40 } 41 42 unmarkCurrentPage(); 43 39 44 _pageNum = n; 40 _chunkNum = int((_pageNum - 1) / 10) + 1; 41 42 if (_currentChunk > _chunkNum) { 43 _currentChunk = _chunkNum; 44 } 45 45 46 refreshChunkNum(); 47 refreshCurrentChunk(); 46 48 refreshButton(); 47 49 markCurrentPage(); … … 64 66 } 65 67 66 /* 67 public function set currentChunk(n:int):void { 68 _currentChunk = n; 69 refreshButton(); 70 } 71 */ 72 68 //---- 69 // buttonNum 70 private var _buttonNum:int = 10; 71 72 /** 73 * チャンクあたりのボタン数 74 */ 75 public function get buttonNum():int { 76 return _buttonNum; 77 } 78 79 public function set buttonNum(n:int):void { 80 if (n <= 0) { 81 return; 82 } 83 84 unmarkCurrentPage(); 85 86 _buttonNum = n; 87 88 refreshChunkNum(); 89 refreshCurrentChunk(); 90 createNumberButton(); 91 refreshButton(); 92 markCurrentPage(); 93 } 94 73 95 //---- 74 96 // currentPage … … 83 105 84 106 public function set currentPage(page:int):void { 107 if (page <= 0 || page > _pageNum) { 108 return; 109 } 110 85 111 unmarkCurrentPage(); 86 112 87 113 _currentPage = page; 88 89 var check:int = isCurrentPageInCurrentChunk();90 if (check < 0) {91 _currentChunk--;92 }93 else if (check > 0) {94 _currentChunk++;95 }96 97 refreshButton();98 114 99 115 var e:PagingChunkEvent = new PagingChunkEvent(PagingChunkEvent.CHANGE_PAGE); … … 101 117 dispatchEvent(e); 102 118 103 markCurrentPage(); 119 refreshCurrentChunk(); 120 refreshButton(); 121 markCurrentPage(); 122 } 123 124 /** 125 * チャンク数を再計算 126 */ 127 private function refreshChunkNum():void { 128 if (_pageNum == 0) { 129 _chunkNum = 0; 130 } 131 else { 132 _chunkNum = int((_pageNum - 1) / buttonNum) + 1; 133 } 134 } 135 136 /** 137 * 現在のチャンクを再計算 138 */ 139 private function refreshCurrentChunk():void { 140 if (_pageNum == 0) { 141 _chunkNum = 0; 142 } 143 else { 144 _currentChunk = int((_currentPage - 1) / buttonNum) + 1; 145 } 104 146 } 105 147 … … 109 151 private function refreshButton():void { 110 152 var i:int; 111 153 /* 154 trace("pageNum: " + pageNum); 155 trace("buttonNum: " + buttonNum); 156 trace("chunkNum: " + _chunkNum); 157 trace("currentPage: " + currentPage); 158 trace("currentChunk: " + currentChunk); 159 */ 112 160 // Page移動ボタンのenabled 113 161 backPageButton.enabled = (currentPage > 1); … … 115 163 116 164 // Chunk移動ボタンのenabled 117 firstChunkButton.enabled = ( _currentChunk >= 2);118 backChunkButton.enabled = ( _currentChunk >= 2);119 nextChunkButton.enabled = ( _currentChunk <= _chunkNum - 1);120 lastChunkButton.enabled = ( _currentChunk <= _chunkNum - 1);165 firstChunkButton.enabled = (currentChunk >= 2); 166 backChunkButton.enabled = (currentChunk >= 2); 167 nextChunkButton.enabled = (currentChunk <= _chunkNum - 1); 168 lastChunkButton.enabled = (currentChunk <= _chunkNum - 1); 121 169 122 170 // 数字ボタンのvisible 123 171 if (_chunkNum == 0) { 124 for (i =1; i<=10; i++) {172 for (i = 0; i < buttonNum; i++) { 125 173 numberButtons[i].visible = false; 126 174 } 127 175 } 128 176 else if (_currentChunk == _chunkNum) { 129 var lastChunkButtonNo:int = _pageNum % 10;177 var lastChunkButtonNo:int = pageNum - (buttonNum * (currentChunk - 1)); 130 178 131 for (i =1; i<=lastChunkButtonNo; i++) {179 for (i = 0; i < lastChunkButtonNo; i++) { 132 180 numberButtons[i].visible = true; 133 181 } 134 182 135 for (i =lastChunkButtonNo+1; i<=10; i++) {183 for (i = lastChunkButtonNo; i < buttonNum; i++) { 136 184 numberButtons[i].visible = false; 137 185 } 138 186 } 139 187 else { 140 for (i =1; i<=10; i++) {188 for (i = 0; i < buttonNum; i++) { 141 189 numberButtons[i].visible = true; 142 190 } … … 144 192 145 193 // 数字ボタンのlabel 146 for (i =1; i<=10; i++) {147 numberButtons[i].label = (_currentChunk - 1) * 10 + i;194 for (i = 0; i < buttonNum; i++) { 195 numberButtons[i].label = (_currentChunk - 1) * buttonNum + i + 1; 148 196 } 149 197 } … … 154 202 private function markCurrentPage():void { 155 203 if (isCurrentPageInCurrentChunk() == 0) { 156 var no:int = currentPage - (_currentChunk - 1) * 10;157 numberButtons[no ].selected = true;204 var no:int = currentPage - (_currentChunk - 1) * buttonNum; 205 numberButtons[no - 1].selected = true; 158 206 } 159 207 } … … 164 212 private function unmarkCurrentPage():void { 165 213 if (isCurrentPageInCurrentChunk() == 0) { 166 var no:int = currentPage - (_currentChunk - 1) * 10;167 numberButtons[no ].selected = false;214 var no:int = currentPage - (_currentChunk - 1) * buttonNum; 215 numberButtons[no - 1].selected = false; 168 216 } 169 217 } … … 174 222 */ 175 223 private function isCurrentPageInCurrentChunk():int { 176 if (currentPage < (_currentChunk - 1) * 10+ 1) {224 if (currentPage < (_currentChunk - 1) * buttonNum + 1) { 177 225 return -1; 178 226 } 179 else if (currentPage > (_currentChunk - 1) * 10 + 10) {227 else if (currentPage > (_currentChunk - 1) * buttonNum + buttonNum) { 180 228 return 1; 181 229 } … … 184 232 } 185 233 } 234 235 /** 236 * 数字ボタンを作成 237 */ 238 private function createNumberButton():void { 239 var i:int; 240 241 for (i = 0; i < numberButtons.length; i++) { 242 removeChild(numberButtons[i]); 243 } 244 numberButtons = new Array(); 245 246 for (i = 0; i < buttonNum; i++) { 247 var button:Button = new Button(); 248 button.name = "b" + (i + 1).toString(); 249 button.percentWidth = 100; 250 button.percentHeight = 100; 251 button.toggle = true; 252 button.styleName = "pcButton"; 253 button.addEventListener(MouseEvent.CLICK, function(event:Event):void 254 { 255 numberButtonClickHandler(event, event.target.name.substr(1)); 256 } 257 ); 258 259 addChildAt(button, 4 + i); 260 numberButtons[i] = button; 261 } 262 } 186 263 187 264 /** … … 190 267 */ 191 268 private function onCreationCompleteHandler(event:Event):void { 192 numberButtons[1] = b1; 193 numberButtons[2] = b2; 194 numberButtons[3] = b3; 195 numberButtons[4] = b4; 196 numberButtons[5] = b5; 197 numberButtons[6] = b6; 198 numberButtons[7] = b7; 199 numberButtons[8] = b8; 200 numberButtons[9] = b9; 201 numberButtons[10] = b10; 202 269 createNumberButton(); 203 270 refreshButton(); 204 271 } … … 297 364 unmarkCurrentPage(); 298 365 299 var newCurrentPage:int = (_currentChunk - 1) * 10+ page;366 var newCurrentPage:int = (_currentChunk - 1) * buttonNum + page; 300 367 301 368 var e:PagingChunkEvent = new PagingChunkEvent(PagingChunkEvent.NUMBER_BUTTON_CLICK); … … 305 372 currentPage = newCurrentPage; 306 373 307 refreshButton();308 374 markCurrentPage(); 309 375 } … … 314 380 <mx:Button id="backChunkButton" label="<" width="100%" height="100%" styleName="pcButton" click="backChunkButtonClickHandler(event);"/> 315 381 <mx:Spacer width="5"/> 316 <mx:Button id="backPageButton" label="前へ" click="backPageButtonClickHandler(event);"/> 317 <mx:Button id="b1" label="1" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 1);"/> 318 <mx:Button id="b2" label="2" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 2);"/> 319 <mx:Button id="b3" label="3" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 3);"/> 320 <mx:Button id="b4" label="4" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 4);"/> 321 <mx:Button id="b5" label="5" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 5);"/> 322 <mx:Button id="b6" label="6" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 6);"/> 323 <mx:Button id="b7" label="7" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 7);"/> 324 <mx:Button id="b8" label="8" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 8);"/> 325 <mx:Button id="b9" label="9" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 9);"/> 326 <mx:Button id="b10" label="10" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 10);"/> 327 <mx:Button id="nextPageButton" label="次へ" click="nextPageButtonClickHandler(event);"/> 382 <mx:Button id="backPageButton" label="前へ" width="100%" click="backPageButtonClickHandler(event);"/> 383 <mx:Button id="nextPageButton" label="次へ" width="100%" click="nextPageButtonClickHandler(event);"/> 328 384 <mx:Spacer width="5"/> 329 385 <mx:Button id="nextChunkButton" label=">" width="100%" height="100%" styleName="pcButton" click="nextChunkButtonClickHandler(event);"/> -
lang/actionscript/PagingChunk/trunk/test.mxml
r4489 r21457 1 <?xml version="1.0"?> 2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:genms.controls="genms.controls.*" creationComplete="pagingChunk.pageNum = 46;"> 1 <?xml version="1.0"?> 2 <mx:Application 3 xmlns:mx="http://www.adobe.com/2006/mxml" 4 xmlns:genms.controls="genms.controls.*" 5 width="800" 6 height="600" 7 creationComplete="pagingChunk.pageNum = 46;" 8 > 9 <mx:Script> 10 <![CDATA[ 11 private function apply():void { 12 pagingChunk.pageNum = int(pageNum.text); 13 pagingChunk.buttonNum = int(buttonNum.text); 14 pagingChunk.currentPage = int(currentPage.text); 15 } 16 ]]> 17 </mx:Script> 18 3 19 <genms.controls:PagingChunk id="pagingChunk" width="100%" numberButtonClick="textArea.text += event.page + '\n';"/> 20 21 <mx:Spacer height="50"/> 4 22 5 <mx:TextArea id="textArea" width="200" height="300"/> 6 <mx:Button label="clear" click="textArea.text = '';"/> 23 <mx:HBox> 24 <mx:Panel title="テスト表示" height="400"> 25 <mx:TextArea id="textArea" width="250" height="100%"/> 26 <mx:Button label="clear" click="textArea.text = '';"/> 27 </mx:Panel> 28 29 <mx:Panel title="プロパティ変更" height="400"> 30 <mx:Form defaultButton="{applyButton}"> 31 <mx:FormItem label="ページ数"> 32 <mx:TextInput id="pageNum" text="46" /> 33 </mx:FormItem> 34 <mx:FormItem label="チャンクあたりのボタン数"> 35 <mx:TextInput id="buttonNum" text="10" /> 36 </mx:FormItem> 37 <mx:FormItem label="現在のページ"> 38 <mx:TextInput id="currentPage" text="1" /> 39 </mx:FormItem> 40 <mx:FormItem> 41 <mx:Button id="applyButton" label="適用" click="apply();" /> 42 </mx:FormItem> 43 </mx:Form> 44 </mx:Panel> 45 </mx:HBox> 7 46 </mx:Application>
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)