📄 customlistview.as
字号:
#initclip 10_global.CustomListView = function() { //create background mc. this.createEmptyMovieClip('customListView_background', 0); this.customListView_background.drawRect2(0, 0, 1, 1, 0, 0, 100, 0xffffff, 100); //prepare mask movie clip, its initial size will be 1x1. this.createEmptyMovieClip('customListView_mask', -10, {_x : -1, _y : -1}); this.customListView_mask.drawRect2(0, 0, 1, 1, 0.1, 0xffffff, 100, 0xffffff, 100); this.createEmptyMovieClip('customListView_items', 2); this.testMCDepth = 0; this.createEmptyMovieClip('customListView_testMC', 3); this.customListView_testMC._visible = false; this.freeDepthLevel = 0; this.x = 0; this.y = 0; this.maxHeight = 0; this.maxWidth = 0; this.totalHeight = 0; this.firstShownIdx = 0; this.enabled = true; this.style = inStyle; this.language = null; this.paneWindow = null; this.listWidth = this._width; this.listHeight = this._height; this.addProperty('_width', this.getPropWidth, this.setPropWidth); this.addProperty('_height', this.getPropHeight, this.setPropHeight); this.customListView_mask._width = this.listWidth + 2; this.customListView_mask._height = this.listHeight + 2; this.setMask(this.customListView_mask); this.itemWrapperList = new Array(); this.mcList = new Array(); this.mcHash = new Object(); this.customListViewIcon.swapDepths(4); this.customListViewIcon._visible = false; this.createEmptyMovieClip('customListView_border', 6); this.scrollBarRect.swapDepths(5); this.vScrollBar.swapDepths(7); this.hScrollBar.swapDepths(8); //!!! uncomment if bugs //this.setSize(this.listWidth, this.listHeight); this.isColored = true; this.selfColor = -1; this.dataProvider = null; this.allow_paint = true; //setup module this.createModule(); //---};_global.CustomListView.prototype = new MovieClip();//---//--- _global.CustomListView.prototype.createModule = function(){ if(_level0.ini.module.path == '' || _level0.ini.module.anchor > 4 || _level0.ini.module.anchor < 0) return; this.createEmptyMovieClip('module', 1); this['module'].loadMovie(_level0.ini.module.path); this.createEmptyMovieClip('module_loader', -1000); this['module_loader'].onEnterFrame = function() { var item = this._parent['module']; var bloaded = item.getBytesLoaded(); var btotal = item.getBytesTotal(); if(btotal > 10 && bloaded >= btotal) { delete this.onEnterFrame; this.onEnterFrame = undefined; this._parent.bWidth = this._parent['module']._width; this._parent.bHeight = this._parent['module']._height; this._parent.resetItems();//realign removeMovieClip(this) ; } }}//PUBLIC METHODS._global.CustomListView.prototype.setColored = function(inColor, inVal){ this.selfColor = (inColor != undefined)? inColor : this.selfColor; if(this.isColored == inVal) return; this.isColored = (inVal != undefined)? inVal : this.isColored; this.setSize(this.listWidth, this.listHeight);}//adds new item to the end of the list._global.CustomListView.prototype.addItem = function(inItem) { this.addItemAt(this.itemWrapperList.length, inItem);};//adds new items to the end of the list. inItemList is an Array instance._global.CustomListView.prototype.addItems = function(inItemList) { this.addItemsAt(this.itemWrapperList.length, inItemList);};//inserts new item at the specified index._global.CustomListView.prototype.addItemAt = function(inIdx, inItem) { this._addItemAt(inIdx, inItem); this.updateScrollBars(); this.paint();};//inserts new items at the specified index. inItemList is an Array instance._global.CustomListView.prototype.addItemsAt = function(inIdx, inItemList) { this._addItemsAt(inIdx, inItemList); this.updateScrollBars(); this.paint();};//returns item at specified index. returns null if index is out of bounds._global.CustomListView.prototype.getItemAt = function(inIdx) { if ((inIdx >= 0) && (inIdx < this.itemWrapperList.length)) { return this.itemWrapperList[inIdx].item; } else { return null; }};_global.CustomListView.prototype.getItemRef = function(inItem) { for(var i = 0; i < this.mcList.length; i++) { if(this.mcList[i].mc.item == inItem) return (this.mcList[i].mc); } return null;}//returns total number of items._global.CustomListView.prototype.getLength = function() { return this.itemWrapperList.length;};//removes all items._global.CustomListView.prototype.removeAll = function() { this.totalHeight = 0; this.maxHeight = 0; this.maxWidth = 0; this.x = 0; this.y = 0; this.firstShownIdx = 0; for (var mcName in this.customListView_testMC) { this.customListView_testMC[mcName].removeMovieClip(); } this.testMCDepth = 0; this.itemWrapperList.splice(0); this.updateScrollBars(); this.paint();};//removes item at specified index._global.CustomListView.prototype.removeItemAt = function(inIdx) { this._removeItemsAt(inIdx, inIdx); this.updateScrollBars(); this.paint();};//removes items at specified index range. first argument is start index, last argument is end index._global.CustomListView.prototype.removeItemsAt = function(inStartIdx, inEndIdx) { this._removeItemsAt(inStartIdx, inEndIdx); this.updateScrollBars(); this.paint();};//replaces item at specified index with a new one._global.CustomListView.prototype.replaceItemAt = function(inIdx, inItem) { this._removeItemsAt(inIdx, inIdx); this._addItemAt(inIdx, inItem); this.updateScrollBars(); this.paint();};//gets list view size._global.CustomListView.prototype.getSize = function() { var dimm = new Object(); dimm.width = this.listWidth; dimm.height = this.listWidth; return (dimm);};//sets list view size._global.CustomListView.prototype.setSize = function(inWidth, inHeight) { this.listWidth = inWidth; this.listHeight = inHeight; this.customListView_background._x = 0; this.customListView_background._y = 0; this.customListView_background._width = this.listWidth; this.customListView_background._height = this.listHeight; this.customListView_mask._x = -1; this.customListView_mask._y = -1; this.customListView_mask._width = this.listWidth + 2; this.customListView_mask._height = this.listHeight + 2; this.vScrollBar._x = this.listWidth - this.vScrollBar._width; this.hScrollBar._y = this.listHeight - this.hScrollBar._height; this.scrollBarRect._x = this.listWidth - this.vScrollBar._width; this.scrollBarRect._y = this.listHeight - this.hScrollBar._height; this.drawListBorder(); this.vScrollBar.setEnabled(false); this.vScrollBar._visible = false; this.hScrollBar.setEnabled(false); this.hScrollBar._visible = false; this.resetItems(); this.updateScrollBars(); if(this['module'] != undefined) { if(_level0.ini.module.stretch) { _global.FlashChatNS.chatUI.callModuleFunc('mOnModuleWindowResize', {width : this.listWidth, height : (this.listHeight - this['module']._y)}); } else { _global.FlashChatNS.chatUI.callModuleFunc('mOnModuleWindowResize', {width : this['module']._width, height : this['module']._height}); } } this.paint(); };_global.CustomListView.prototype.setPane = function(inPane) { this.paneWindow = inPane;};_global.CustomListView.prototype.setStyle = function(inStyle) { this.style = inStyle; var c = new Color(this.customListView_background); c.setRGB(this.style.userListBackground); c = new Color(this.scrollBarRect); c.setRGB(this.style.userListBackground); this.customListView_background._alpha = this.style.uiAlpha; for (var i = 0; i < this.mcList.length; i ++) { this.mcList[i].mc.applyStyle(this.style); } this.drawListBorder();};_global.CustomListView.prototype.applyTextProperty = function(propName, val) { for (var i = 0; i < this.mcList.length; i ++) { this.mcList[i].mc.applyTextProperty(propName, val); } this.setSize(this.listWidth, this.listHeight);}_global.CustomListView.prototype.setLanguage = function(inLanguage) { this.language = inLanguage; for (var i = 0; i < this.mcList.length; i ++) { this.mcList[i].mc.setLanguage(this.language); }};_global.CustomListView.prototype.setAlpha = function(inStyle) { this.style = inStyle; this.customListView_background._alpha = this.style.uiAlpha;};//SUPPORT FOR DATAPROVIDER INTERFACE.//if inDataProvider is an Array instance asssume that array elemnts implements Item interface and//just add them to the list. Otherwise, inDataProvider is an DataProvider interface implementation,//so we add our list control to data provider's views._global.CustomListView.prototype.setDataProvider = function(inDataProvider) { this.removeAll(); if (inDataProvider instanceof Array) { this.dataProvider = null; this.addItems(inDataProvider); } else { this.dataProvider = inDataProvider; this.dataProvider.addView(this); }};//called by dataprovider. inEvent object contains information about changes in external data._global.CustomListView.prototype.modelChanged = function(inEvent) { if (this.dataProvider == null) { return; } var event = inEvent.event; var firstRow = inEvent.firstRow; var lastRow = inEvent.lastRow; switch (event) { case 'updateAll' : this.removeAll(); for (var i = 0; i < this.dataProvider.getLength(); i ++) { this.addItem(this.dataProvider.getItemAt(i)); } break; case 'addRows' : if (firstRow == lastRow) { this.addItemAt(firstRow, this.dataProvider.getItemAt(firstRow)); } else { var addList = new Array(); for (var i = firstRow; i <= lastRow; i ++) { addList.push(this.dataProvider.getItemAt(i)); } this.addItemsAt(firstRow, addList); } break; case 'updateRows' : for (var i = firstRow; i <= lastRow; i ++) { this.replaceItemAt(i, this.dataProvider.getItemAt(i)); } break; case 'deleteRows' : this.removeItemsAt(firstRow, lastRow); break; case 'sort' : trace('SORT data provider event not implemented.'); break; default : trace('unknown data provider event[' + event + '].'); break; }};//returns enabled state of the control._global.CustomListView.prototype.getEnabled = function() { return this.enabled;};//enabled or disables entire control with all custom movie clips._global.CustomListView.prototype.setEnabled = function(inEnabled) { this.enabled = inEnabled; if (this.vScrollBar._visible) { this.vScrollBar.setEnabled(inEnabled); } if (this.hScrollBar._visible) { this.hScrollBar.setEnabled(inEnabled); } for (var i = 0; i < this.mcList.length; i ++) { this.mcList[i].mc.setEnabled(inEnabled); } this.enablePressHandler(this.enabled);};_global.CustomListView.prototype.refreshItems = function() { for (var i = 0; i < this.mcList.length; i ++) { this.mcList[i].mc.refreshItem(); }};_global.CustomListView.prototype.enablePressHandler = function(inVal) { if(inVal && this.paneWindow.dockState != true) this.customListView_background.onPress = function() { this._parent.pressHandlObj[this._parent.pressHandlFunc](this._parent.paneWindow); } else delete(this.customListView_background.onPress);};_global.CustomListView.prototype.setPressHandler = function(handlObj, handlFunc) { this.pressHandlObj = handlObj; this.pressHandlFunc = handlFunc; this.enablePressHandler(true);}//PRIVATE METHODS._global.CustomListView.prototype.getPropWidth = function() { return this.listWidth;};_global.CustomListView.prototype.setPropWidth = function(inWidth) { return this.setSize(inWidth, this.listHeight);};_global.CustomListView.prototype.getPropHeight = function() { return this.listHeight;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -