Whoops, that was stupid.

Change 'index' to 'i' in the for statement condition and incrementor.

2009/4/27 Tracy Spratt <tr...@nts3rd.com>:
>
>
> A hint, look closely at this syntax:
>
> for (var i:int = 0; index < courses.length; index++)
>
> See the problem?
>
>
>
> Tracy Spratt,
>
> Lariat Services, development services available
>
> ________________________________
>
> From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
> Behalf Of Sam Lai
> Sent: Sunday, April 26, 2009 8:21 PM
>
> To: flexcoders@yahoogroups.com
> Subject: Re: [flexcoders] getItemIndex ......returning -1
>
>
>
>
> I'm on my phone so I can't see the entirety of the reply, but I used a
> variable named i as well as one named index so you know if a match has
> been found or not. If index = -1, it means no match has been found.
>
> If it is always giving you -1, it is because the if statement inside
> the loop isn't evaluating to true to any item within the array.
>
> See if you can figure it out, maybe using the Flex Debugger.
> Otherwise, we'll need to see how you create the objects in the list,
> and how you add them to the list.
>
> On 4/27/09, Tracy Spratt <tr...@nts3rd.com> wrote:
>> Your if statement is wrong, decide whether you are going to use "I" or
>> "index".
>>
>>
>>
>> Tracy Spratt,
>>
>> Lariat Services, development services available
>>
>> _____
>>
>> From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
>> Behalf Of joe.g.ja...@kp.org
>> Sent: Sunday, April 26, 2009 1:24 PM
>> To: flexcoders@yahoogroups.com
>> Subject: Re: [flexcoders] getItemIndex ......returning -1
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Thank you, but for some reason the index variable is providing me with a
>> -1
>> value, so the if statement is never true.
>>
>> var index:int = -1;
>> for (var i:int = 0; index < courses.length; index++)
>> { -1
>> if (courses.getItemAt(index).TITLE == "specific course name")
>> {
>> index = i;
>> break;
>> }
>> }
>>
>>
>>
>>
>>
>> Sam Lai <samuel....@gmail.com>
>> Sent by: flexcoders@yahoogroups.com
>>
>> 04/26/2009 12:59 AM
>>
>>
>> Please respond to
>> flexcoders@yahoogroups.com
>>
>>
>> To
>>
>> flexcoders@yahoogroups.com
>>
>>
>> cc
>>
>>
>>
>>
>> Subject
>>
>> Re: [flexcoders] getItemIndex ......returning -1
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Flex is looking for a string in the array with the value 'specific
>> course name'. In your arraycollection though, you have objects (not
>> strings), which within them hold multiple strings (TITLE, DESC, REQ).
>>
>> The only way to match again the title field of every object in the
>> array is to use a for loop, e.g.
>>
>> var index:int = -1;
>> for (var i:int = 0; index < courses.length; index++)
>> {
>> if (courses.getItemAt(index).TITLE == "specific course name")
>> {
>> index = i;
>> break;
>> }
>> }
>>
>> if (index < 0)
>> trace("no course found by that name");
>> else
>> trace("course found");
>>
>> 2009/4/26 kpjj31 <joe.g.james@ <mailto:joe.g.james%40kp.org> kp.org>:
>>> What am I doing wrong. Thanks.
>>>
>>> private function getcoursesResult(event:ResultEvent):void{
>>>
>>> courses = new ArrayCollection (event.result.COURSELIST as Array);
>>>
>>> var newindex:int = courses.getItemIndex('specific course name');
>>>
>>> courses_datagrid.selectedIndex=newindex;
>>> }
>>>
>>> arraycollection example...
>>>
>>> COURSELIST
>>> + 0
>>> - 1
>>> TITLE : 'specific course name'
>>> DESC : ''
>>> REQ : ''
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------
>>>
>>> --
>>> Flexcoders Mailing List
>>> FAQ: http://groups.
>> <http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt>
>> yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
>>> Alternative FAQ location: https://share.
>>
>> <https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e6
>> 2079f6847>
>> acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
>>> Search Archives: http://www.mail-
>> <http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo>
>> archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>
>>
>
> --
> Sent from my mobile device
>
> 

Reply via email to