This code is *untested* and I don't stand behind it yet, hence there being
no actual release. However, feel free to have a crack at it. I do know it
works for simple cases, but haven't tested the advanced stuff, like indexing
something that has a filter or sort applied to it. It *should* work however:
http://www.gfunk007.com/flex/ListIndexer.as

It's not an implementation of IList or anything, you construct it, tell it
what you want it to watch, and what they key field is, and it'll keep track
of it for you. ListIndexer.keyExists() and ListIndexer.getIndex() are what
it does. You just call:

listIndexer = new ListIndexer(indexedCollection, "keyField");

//... Populate indexedCollection, whaterver....

indexedCollection.getItemAt(listIndexer.getIndex(keyValue));

If you find a bug, please let me know. Once crunch-time is over, I'll
organise with the boss to get an official place to put these util classes
-with unit tests- (and monkey-patches for Flex's SOAP code) we're going to
release, as well as some stuff I'm doing in my own time.

-Josh

On Wed, Jun 11, 2008 at 12:13 PM, Corey Osman <[EMAIL PROTECTED]> wrote:

>   I just stumbled upon such a technique last night as I was having trouble
> accessing array collection elements directly since I was trying to use it
> like an array.
> If you use IViewCursor class and a filter class you can achieve everything
> you want .  You can see how I did this below.  My old code was easily twice
> as long and non-working.
> Look at the "using data providers and collections"  in the flex 3 docs.
>
>
> protected var valves:ArrayCollection = new ArrayCollection([
>
> {ptype:"exhaust",location:"cylinder 3 (right)", clearance:0.00,
> shimsize:000, newshimsize:000 ,newclearance:0.25},
> {ptype:"exhaust",location:"cylinder 3 (left)", clearance:0.00,
> shimsize:000, newshimsize:000 ,newclearance:0.25},
> {ptype:"exhaust",location:"cylinder 4 (right)", clearance:0.00,
> shimsize:000, newshimsize:000 ,newclearance:0.25},
> {ptype:"exhaust",location:"cylinder 4 (left)", clearance:0.00,
> shimsize:000, newshimsize:000 ,newclearance:0.25}]);
>
> private function onBikeChange(event:Event):void{
> //used to change bike clearance
> //get selected bike
>  var selected:String = ComboBox(event.target).selectedItem.data;
>  var inc:Number;
>  var exc:Number;
>  var cursor:IViewCursor;
>  var thedata:Object;
>
>  switch (selected){
> case "FZR400":
> inc = .15;
> exc = .25;
> break;
> case "FZR600":
> inc = .15;
> exc = .25;
> break;
> case "FZR1000":
> inc = .15;
> exc = .25;
> break;
> }
>
> // get the cursor from the array collection
> cursor = valves.createCursor();
> while(! cursor.afterLast){
>
>  if (cursor.current.ptype == "intake")
> cursor.current.newclearance = inc;
>
>
> if (cursor.current.ptype == "exhaust")
> cursor.current.newclearance = exc;
>
>
> cursor.moveNext();
> }
>
>
> valves.refresh();
> }
>
> http://www.logicminds.biz/motorcycles/shimulator.html
>
>  
>



-- 
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]

Reply via email to