原文:http://kb2.adobe.com/community/publishing/526/cpsid_52633.html
carDealers结构图如下:
var carDealers:ArrayCollection;
var dealerCursor:IViewCursor;
var vehicleCursor:IViewCursor;
var affectedDealer:CarDealer;
var targetVehicle:Car;
var targetVehicleIndex:Number;
var dealerIdFromSale:String = 'XXXXXXXX-XXXX-XXXX-XXXXXXXXXXX';
var vinNumberFromSale:String = 'XXXXXXXXXXXXXXXXX';
dealerCursor = carDealers.createCursor();
// iterate through the list of dealers
while (!dealerCursor.afterLast)
{
if (dealerCursor.current.dealerId == dealerIdFromSale)
{
affectedDealer = CarDealer( dealerCursor.current );
// create a cursor to iterate over the dealer's inventory
vehicleCursor = affectedDealer.inventory.createCursor();
// iterate over the inventory
while (!vehicleCursor.afterLast)
{
if (vehicleCursor.current.VIN == vinNumberFromSale)
{
// a match was found so now we need the
// index of this vehicle in the ArrayCollection
targetVehicle = Car( vehicleCursor.current );
targetVehicleIndex = affectedDealer.inventory.getItemIndex( targetVehicle );
// since the sale was successful, we can safely
// remove the vehicle from this dealer's inventory
affectedDealer.inventory.removeItemAt( targetVehicleIndex );
}
vehicleCursor.moveNext();
}
}
dealerCursor.moveNext();
}
主要代码如下:
dealerCursor = carDealers.createCursor();
// iterate through the list of dealers
while (!dealerCursor.afterLast)
{
// dealerCursor.current.dealerId 获取游标当前值
dealerCursor.moveNext();
}