air mobile andriod ios 分頁載入控制項
近來研究用flex 寫android 、ios應用,遇到了一個分頁載入的問題,我們用的是flex sdk 12,air 15 沒有找到類似android ListView分頁組件,所以就和同事自己寫了個,效果還是可以的,向上拖動重新整理,向下拖動載入。如果有感興趣的朋友可以拿走,如果你有更好的通知我一聲,代碼就直接帖出來吧。
import mx.events.PropertyChangeEvent;private static const PADDING:uint = 15;private function init():void {updateList();_list.dataGroup.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, handleScroll);}private function handleScroll(event:PropertyChangeEvent):void {if (_busy.visible || _busy_x.visible || event.source != event.target || event.property != 'verticalScrollPosition') {return;}//下拉 載入 if (event.newValue < -3 * PADDING && event.oldValue >= -3 * PADDING) {_hintDown.visible = true;_hintUp.visible = false;_fadeIn.play([_hintDown]);} else if (event.newValue < -6 * PADDING && event.oldValue >= -6 * PADDING) {_hintDown.visible = false;_hintUp.visible = true;_fadeIn.play([_hintUp]);} else if (event.newValue >= -6 * PADDING && event.oldValue < -6 * PADDING) {_hintDown.visible = true;_hintUp.visible = false;_fadeIn.play([_hintDown]);} else if (event.newValue >= -3 * PADDING && event.oldValue < -3 * PADDING) {_hintDown.visible = false;_hintUp.visible = false;}//上拉重新整理 載入 if (event.newValue < 3 * PADDING && event.oldValue >= 3 * PADDING) {_hintDown_up.visible = false;_hintUp_up.visible = false;} else if (event.newValue < 6 * PADDING && event.oldValue >= 6 * PADDING) {_hintDown_up.visible = false;_hintUp_up.visible = false;}else if (event.newValue >= 6 * PADDING && event.oldValue < 6 * PADDING) {_hintDown_up.visible = false;_hintUp_up.visible = true;_fadeIn.play([_hintUp_up]);}else if (event.newValue >= 3 * PADDING && event.oldValue < 3 * PADDING) {_hintDown_up.visible = true;_hintUp_up.visible = false;_fadeIn.play([_hintDown_up]);}}private function startLoading(event:MouseEvent):void {//下拉 載入方法if (_hintUp.visible) {_busy.includeInLayout = _busy.visible = true;if(_hintDown.visible)_busy_x.includeInLayout = _busy_x.visible = true;setTimeout(updateList, 1000);}_hintDown.visible = false;_hintUp.visible = false;//上拉 載入方法if (_hintUp_up.visible) {_busy_x.includeInLayout = _busy_x.visible = true;if(_hintDown_up.visible)_busy_x.includeInLayout = _busy_x.visible = true;setTimeout(updateList, 1000);}_hintDown_up.visible = false;_hintUp_up.visible = false;}private function updateList():void {_ac.source = new Array();for (var i:int = 0; i < 10; i++) {_ac.source.push(Math.random());}_ac.refresh();_busy.includeInLayout = _busy.visible = false;_busy_x.includeInLayout = _busy_x.visible = false;}