| <?xml version="1.0" encoding="utf-8"?> |
| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| |
| --> |
| <s:Group |
| xmlns:fx="http://ns.adobe.com/mxml/2009" |
| xmlns:mx="library://ns.adobe.com/flex/mx" |
| xmlns:s="library://ns.adobe.com/flex/spark" |
| xmlns:local="assets.*"> |
| |
| <!-- |
| This one has useVirtualLayout = false. |
| --> |
| |
| <fx:Script> |
| <![CDATA[ |
| |
| import flash.events.Event; |
| import mx.collections.*; |
| import mx.collections.errors.*; |
| import mx.events.CollectionEvent; |
| import spark.components.*; |
| import spark.components.supportClasses.DropDownController; |
| |
| import flash.events.TimerEvent; |
| import flash.utils.Timer; |
| |
| private var t:Timer; |
| |
| // These are new in this component so we can sort. |
| public var lcv:ListCollectionView; |
| public var theSort:Sort; |
| |
| // Public so we can access it, e.g., to be sure it dispatches events. |
| public var alv:AsyncListView; |
| |
| // The ever famous simulator. |
| public var theSimulator:ItemPendingErrorSimulator; |
| |
| // Added items start at 5000 so we can tell which ones those are. |
| public var addedItems:int = 5000; |
| |
| // To use as a local data provider. |
| public var ac:ArrayCollection = new ArrayCollection([{info:'thing 0'},{info:'thing 1'},{info:'thing 2'},{info:'thing 3'},{info:'thing 4'}]); |
| |
| /** |
| * This allows you to set a bunch of parameters. |
| **/ |
| public function setup( responseDelay:int = 500, |
| numItems:int = 100, |
| numPreloadedPages:int = 0, |
| pageSize:int = 1, |
| mode:String = 'manual', |
| failureProbability:int = 0, |
| createPendingItemFunction:Boolean = true, |
| createFailedItemFunction:Boolean = true):void{ |
| |
| theSimulator = new ItemPendingErrorSimulator(); |
| |
| theSimulator.responseDelay = responseDelay; |
| theSimulator.numItems = numItems; |
| theSimulator.numPreloadedPages = numPreloadedPages; |
| theSimulator.pageSize = pageSize; |
| theSimulator.mode = mode; |
| theSimulator.failureProbability = failureProbability; |
| theSimulator.objectFactory = theObjectFactory; |
| theSimulator.reset(); |
| |
| alv = new AsyncListView(theSimulator); |
| |
| if(createPendingItemFunction) |
| alv.createPendingItemFunction = pendingFunction; |
| |
| if(createFailedItemFunction) |
| alv.createFailedItemFunction = errorFunction; |
| |
| lcv = new ListCollectionView(alv); |
| |
| theList.dataProvider = lcv; |
| } |
| |
| /** |
| * This allows you to set a bunch of parameters and |
| * specify the pending and error functions. |
| **/ |
| public function setup2( responseDelay:int = 500, |
| numItems:int = 100, |
| numPreloadedPages:int = 0, |
| pageSize:int = 1, |
| mode:String = 'manual', |
| failureProbability:int = 0, |
| createPendingItemFunction:Function = null, |
| createFailedItemFunction:Function = null):void{ |
| |
| theSimulator = new ItemPendingErrorSimulator(); |
| |
| theSimulator.responseDelay = responseDelay; |
| theSimulator.numItems = numItems; |
| theSimulator.numPreloadedPages = numPreloadedPages; |
| theSimulator.pageSize = pageSize; |
| theSimulator.mode = mode; |
| theSimulator.failureProbability = failureProbability; |
| theSimulator.objectFactory = theObjectFactory; |
| theSimulator.reset(); |
| |
| alv = new AsyncListView(theSimulator); |
| |
| if(createPendingItemFunction != null) |
| alv.createPendingItemFunction = createPendingItemFunction; |
| |
| if(createFailedItemFunction != null) |
| alv.createFailedItemFunction = createFailedItemFunction; |
| |
| theList.dataProvider = alv; |
| } |
| |
| /** |
| * This setup updates the original AsyncListView object |
| * instead of replacing it. |
| **/ |
| public function setup3( responseDelay:int = 500, |
| numItems:int = 100, |
| numPreloadedPages:int = 0, |
| pageSize:int = 1, |
| mode:String = 'manual', |
| failureProbability:int = 0, |
| createPendingItemFunction:Boolean = true, |
| createFailedItemFunction:Boolean = true):void{ |
| |
| theSimulator = new ItemPendingErrorSimulator(); |
| |
| theSimulator.responseDelay = responseDelay; |
| theSimulator.numItems = numItems; |
| theSimulator.numPreloadedPages = numPreloadedPages; |
| theSimulator.pageSize = pageSize; |
| theSimulator.mode = mode; |
| theSimulator.failureProbability = failureProbability; |
| theSimulator.objectFactory = theObjectFactory; |
| theSimulator.reset(); |
| |
| alv.list = theSimulator; |
| |
| if(createPendingItemFunction) |
| alv.createPendingItemFunction = pendingFunction; |
| |
| if(createFailedItemFunction) |
| alv.createFailedItemFunction = errorFunction; |
| |
| theList.dataProvider = alv; |
| } |
| |
| public function pendingFunction(i:int, obj:Object):Object{ |
| return {info: "item " + i.toString() + " pending", status: "pending"}; |
| } |
| |
| public function errorFunction(i:int, obj:Object):Object{ |
| return {info: "item " + i.toString() + " failed", status: "failed"}; |
| } |
| |
| public function theObjectFactory(i:int):Object{ |
| return {info: "item " + i.toString() + " present", status: "present"}; |
| } |
| |
| public function sort(reverse:Boolean = false):void{ |
| theSort = new Sort(); |
| theSort.fields = [new SortField("info", true)]; |
| |
| if(reverse) |
| theSort.reverse(); |
| |
| lcv.sort = theSort; |
| lcv.refresh(); |
| } |
| |
| public function doTest():void{ |
| setup(); |
| theList.openDropDown(); |
| |
| t = new Timer(2000); |
| t.addEventListener(TimerEvent.TIMER, handleTimerEvent); |
| t.start(); |
| } |
| |
| public function handleTimerEvent(obj:*):void{ |
| trace("theList.dataGroup.getElementAt(0).label: " + Object(theList.dataGroup.getElementAt(0)).label); |
| |
| } |
| |
| ]]> |
| </fx:Script> |
| <s:VGroup> |
| <s:ComboBox id="theList" useVirtualLayout="true" labelField="info" /> |
| </s:VGroup> |
| </s:Group> |