📄 storeitemcollectionview.as
字号:
package mx.item.view
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import mx.item.collection.StoreItemCollection;
import mx.ui.ScrollButton;
public class StoreItemCollectionView extends Sprite
{
private var _data:StoreItemCollection;
private var _frame:Sprite;
private var _contents:Sprite;
private var _mask:Sprite;
private var _arrowUp:ScrollButton;
private var _arrowDown:ScrollButton;
private var _mouseDownEventHandler:Function;
public function StoreItemCollectionView(data:StoreItemCollection, mouseDownEventHandler:Function):void
{
_data = data;
_mouseDownEventHandler = mouseDownEventHandler;
_data.addEventListener(Event.CHANGE,onUpdate);
_frame = new Sprite();
_frame.graphics.lineStyle(0, 0x000000, 1);
_frame.graphics.beginFill(0x00FF00,0);
_frame.graphics.drawRect(0,0,320,480);
_frame.graphics.endFill();
this.addChild(_frame);
_mask = new Sprite();
_mask.graphics.lineStyle();
_mask.graphics.beginFill(0xFF00FF, 1);
_mask.graphics.drawRect(0,0,320,480);
_mask.graphics.endFill();
this.addChild(_mask);
_arrowUp = new ScrollButton(1);
_arrowUp.x = 320;
this.addChild(_arrowUp);
_arrowDown = new ScrollButton(0);
_arrowDown.x =320;
this.addChild(_arrowDown);
_arrowDown.y = 480 - _arrowDown.height;
_arrowUp.addEventListener(MouseEvent.CLICK, onScrollUp);
_arrowDown.addEventListener(MouseEvent.CLICK, onScrollDown);
onUpdate(null);
}
private function onUpdate(event:Event):void {
if(_contents != null) {
removeChild(_contents);
}
_contents = new Sprite();
this.addChild(_contents);
_contents.mask = _mask;
var itemView:StoreItemView;
var itemY:Number = 0;
var i:uint;
for(i = 0; i < _data.count; i++) {
itemView = new StoreItemView(_data.getItem(i));
itemView.addEventListener(MouseEvent.MOUSE_DOWN,_mouseDownEventHandler);
itemView.y = itemY;
_contents.addChild(itemView);
itemY += 120;
}
var scroll:Boolean = _contents.height > _frame.height;
_arrowUp.visible = scroll;
_arrowDown.visible = scroll;
}
private function onScrollUp(event:MouseEvent):void {
if (_contents.y < _frame.y ) {
_contents.y += 120;
}
}
private function onScrollDown(event:MouseEvent):void {
if(_contents.y > - _contents.height + _frame.height) {
_contents.y -= 120;
}
}}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -