[flexcoders] Re: Can't find bug in this piece of ActionScript

2007-02-02 Thread malik_robinson

Hi,

I dont think it does, I could be wrong, but I want to set the
selectedIndex equal to the employeeStateId  so if the employee has a
stateId of say 3 for Arizona or whatever,  I want the selectedIndex to
be 3.

Unless I am missing something.

-M


--- In flexcoders@yahoogroups.com, Ralf Bokelberg [EMAIL PROTECTED]
wrote:

 Doesn't it have to be stateCB.selectedIndex = i;
 Cheers,
 Ralf.

 On 2/2/07, malik_robinson [EMAIL PROTECTED] wrote:
 
  Hi,
 
  I am trying to set the selectedIndex of my U.S. States custom
combo box
  equal to what the user has stored in their record in our database.
Someone
  posted a link to a similar tutorial, but I could not get it to work
and I
  think it seems to be slightly different than what I am doing. When
the
  screen loads, the state the user is associated with should be
selected,
  otherwise set the selectedIndex equal to 0.
 
  As of now it does not select anything it seems the condition where I
test
  for equality fails and I always get the selectedIndex set to 0.
 
  *The code:*
 
  *public function** initStateCB(employeeStateId:Number):void** {*
 
  for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
  if( employeeStateId == stateCB.dataProvider[i].stateId ) {
  stateCB.selectedIndex = employeeStateId ;
  }
  else {
  stateCB.selectedIndex = 0;
  }
  }
 
  *} **// close function*
 
  **
  mx:FormItem label=State:
  comp:StateCombo id=stateCB dataProvider={model.stateList}
  labelField=stateName creationComplete=initStateCB(
  model.employeeProfileArray[0].stateId)/
  /mx:FormItem
 
 
 
 



 --
 Ralf Bokelberg [EMAIL PROTECTED]
 Flex  Flash Consultant based in Cologne/Germany
 Phone +49 (0) 221 530 15 35






Re: [flexcoders] Re: Can't find bug in this piece of ActionScript

2007-02-02 Thread Ralf Bokelberg

Ah sorry, i haven't read the text ;)
What if you try it like that:

var selectedIndex : int = 0;
for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
  if( employeeStateId == stateCB.dataProvider[i].stateId ) {
 selectedIndex = employeeStateId ;
  }
}
stateCB.selectedIndex = selectedIndex;

Cheers,
Ralf.

--
Ralf Bokelberg [EMAIL PROTECTED]
Flex  Flash Consultant based in Cologne/Germany
Phone +49 (0) 221 530 15 35


[flexcoders] Re: Can't find bug in this piece of ActionScript

2007-02-02 Thread malik_robinson

Hi,

The code works the first time around.  First time around meaning click
an employee from the datagrid and the screen changes to a detail view of
that employee.

For some reason every user I bring up after the first user has the same
State (Arizona) for example selected thereafter.  The first time
around it works, but then when I go back to the employee list screen,
and click a different employee, the detail form populates with all the
right info like (firstName, lastName, email, city, zip), but the state
drop down has the value of the state the other user is associated with
(Arizona).

Its as if the code runs correctly once but when you click a different
user the approriate state does not load, it just has the value from the
prior user.  Almost as if once the code runs once,  and its being cached
or something.  All the other fields load correctly as I view each users
detail view.

I hope I am making sense.

-M
--- In flexcoders@yahoogroups.com, Ralf Bokelberg [EMAIL PROTECTED]
wrote:

 Ah sorry, i haven't read the text ;)
 What if you try it like that:

 var selectedIndex : int = 0;
 for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
 if( employeeStateId == stateCB.dataProvider[i].stateId ) {
 selectedIndex = employeeStateId ;
 }
 }
 stateCB.selectedIndex = selectedIndex;

 Cheers,
 Ralf.

 --
 Ralf Bokelberg [EMAIL PROTECTED]
 Flex  Flash Consultant based in Cologne/Germany
 Phone +49 (0) 221 530 15 35






Re: [flexcoders] Re: Can't find bug in this piece of ActionScript

2007-02-02 Thread Ralf Bokelberg

That's probably because the creationComplete event is called just once.
What if you use binding instead?

selectedIndex={ getStateIndex( *employeeStateId:Number, dataProvider:Array*) }

Cheers,
Ralf.



On 2/2/07, malik_robinson [EMAIL PROTECTED] wrote:



Hi,

The code works the first time around. First time around meaning click
an employee from the datagrid and the screen changes to a detail view of
that employee.

For some reason every user I bring up after the first user has the same
State (Arizona) for example selected thereafter. The first time
around it works, but then when I go back to the employee list screen,
and click a different employee, the detail form populates with all the
right info like (firstName, lastName, email, city, zip), but the state
drop down has the value of the state the other user is associated with
(Arizona).

Its as if the code runs correctly once but when you click a different
user the approriate state does not load, it just has the value from the
prior user. Almost as if once the code runs once, and its being cached
or something. All the other fields load correctly as I view each users
detail view.

I hope I am making sense.

-M
--- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Ralf
Bokelberg [EMAIL PROTECTED]
wrote:

 Ah sorry, i haven't read the text ;)
 What if you try it like that:

 var selectedIndex : int = 0;
 for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
 if( employeeStateId == stateCB.dataProvider[i].stateId ) {
 selectedIndex = employeeStateId ;
 }
 }
 stateCB.selectedIndex = selectedIndex;

 Cheers,
 Ralf.

 --
 Ralf Bokelberg [EMAIL PROTECTED]
 Flex  Flash Consultant based in Cologne/Germany
 Phone +49 (0) 221 530 15 35


 





--
Ralf Bokelberg [EMAIL PROTECTED]
Flex  Flash Consultant based in Cologne/Germany
Phone +49 (0) 221 530 15 35


[flexcoders] Re: Can't find bug in this piece of ActionScript

2007-02-02 Thread malik_robinson
Hi,

I am new to actionscript and not quite sure how to implement that
solution you suggested.  It looks like the way to go because I do want
to always have the right state selected when the detail screen first
loads so I presume that is where the binding kicks in.

Here is what I did in the code which I think is wrong how I am
referencing the array in the parameter

public function getStateIndex(employeeStateId:Number,
model.employeeProfileArray[0]:Array):void {
var selectedIndex : int = 0;
for ( var i:int=0; i stateCB.dataProvider.length; i++ )
{
if( getStateIndex(employeeStateId:==
stateCB.dataProvider[i].stateId ) {
   selectedIndex = getStateIndex(employeeStateId:;
}
 }
 stateCB.selectedIndex = selectedIndex;

comp:StateCombo id=stateCB selectedIndex={ getStateIndex(
employeeStateId:Number, model.employeeProfileArray[0]:Array ) }
dataProvider={model.stateList}  labelField=stateName/

I am using Cairngorm 2.1 and it is actually working pretty well for me,
so is there a way to elegantly bind this to the ModelLocator? The array
is bound to the ModelLocator


--- In flexcoders@yahoogroups.com, Ralf Bokelberg [EMAIL PROTECTED]
wrote:

 That's probably because the creationComplete event is called just
once.
 What if you use binding instead?

 selectedIndex={ getStateIndex( *employeeStateId:Number,
dataProvider:Array*) }

 Cheers,
 Ralf.



 On 2/2/07, malik_robinson [EMAIL PROTECTED] wrote:
 
 
  Hi,
 
  The code works the first time around. First time around meaning
click
  an employee from the datagrid and the screen changes to a detail
view of
  that employee.
 
  For some reason every user I bring up after the first user has the
same
  State (Arizona) for example selected thereafter. The first time
  around it works, but then when I go back to the employee list
screen,
  and click a different employee, the detail form populates with all
the
  right info like (firstName, lastName, email, city, zip), but the
state
  drop down has the value of the state the other user is associated
with
  (Arizona).
 
  Its as if the code runs correctly once but when you click a
different
  user the approriate state does not load, it just has the value from
the
  prior user. Almost as if once the code runs once, and its being
cached
  or something. All the other fields load correctly as I view each
users
  detail view.
 
  I hope I am making sense.
 
  -M
  --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com,
Ralf
  Bokelberg ralf.bokelberg@
  wrote:
  
   Ah sorry, i haven't read the text ;)
   What if you try it like that:
  
   var selectedIndex : int = 0;
   for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
   if( employeeStateId == stateCB.dataProvider[i].stateId ) {
   selectedIndex = employeeStateId ;
   }
   }
   stateCB.selectedIndex = selectedIndex;
  
   Cheers,
   Ralf.
  
   --
   Ralf Bokelberg ralf.bokelberg@
   Flex  Flash Consultant based in Cologne/Germany
   Phone +49 (0) 221 530 15 35
  
 
 
 



 --
 Ralf Bokelberg [EMAIL PROTECTED]
 Flex  Flash Consultant based in Cologne/Germany
 Phone +49 (0) 221 530 15 35




Re: [flexcoders] Re: Can't find bug in this piece of ActionScript

2007-02-02 Thread Ralf Bokelberg

Ok, i understand. Ty it like that:

public function getStateIndex( employeeStateId : Number, dataProvider :
Array) : int {
  var selectedIndex : int = 0;
  for ( var i:int=0; i dataProvider.length; i++ ) {
  if( employeeStateId == dataProvider[i].stateId ) {
 selectedIndex = employeeStateId;
  }
   }
   return selectedIndex;
}

comp:StateCombo id=stateCB selectedIndex={ getStateIndex(
model.employeeProfileArray[0].stateId, model.stateList ) } dataProvider={
model.stateList}  labelField=stateName/

Cheers,
Ralf.

On 2/2/07, malik_robinson [EMAIL PROTECTED] wrote:


  Hi,

I am new to actionscript and not quite sure how to implement that solution
you suggested.  It looks like the way to go because I do want to always have
the right state selected when the detail screen first loads so I presume
that is where the binding kicks in.

Here is what I did in the code which I think is wrong how I am referencing
the array in the parameter

public function getStateIndex(employeeStateId:Number,
model.employeeProfileArray[0]:Array):void {
   var selectedIndex : int = 0;
   for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
   if( getStateIndex(employeeStateId:==
stateCB.dataProvider[i].stateId ) {
  selectedIndex = getStateIndex(employeeStateId:;
   }
}
stateCB.selectedIndex = selectedIndex;

comp:StateCombo id=stateCB selectedIndex={ getStateIndex(
employeeStateId:Number, model.employeeProfileArray[0]:Array ) }
dataProvider={model.stateList}  labelField=stateName/

I am using Cairngorm 2.1 and it is actually working pretty well for me, so
is there a way to elegantly bind this to the ModelLocator? The array is
bound to the ModelLocator


--- In flexcoders@yahoogroups.com, Ralf Bokelberg [EMAIL PROTECTED]
wrote:

 That's probably because the creationComplete event is called just once.
 What if you use binding instead?

 selectedIndex={ getStateIndex( *employeeStateId:Number,
dataProvider:Array*) }

 Cheers,
 Ralf.



 On 2/2/07, malik_robinson [EMAIL PROTECTED] wrote:
 
 
  Hi,
 
  The code works the first time around. First time around meaning click
  an employee from the datagrid and the screen changes to a detail view
of
  that employee.
 
  For some reason every user I bring up after the first user has the
same
  State (Arizona) for example selected thereafter. The first time
  around it works, but then when I go back to the employee list screen,
  and click a different employee, the detail form populates with all the
  right info like (firstName, lastName, email, city, zip), but the state
  drop down has the value of the state the other user is associated with
  (Arizona).
 
  Its as if the code runs correctly once but when you click a different
  user the approriate state does not load, it just has the value from
the
  prior user. Almost as if once the code runs once, and its being cached
  or something. All the other fields load correctly as I view each users
  detail view.
 
  I hope I am making sense.
 
  -M
  --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com,
Ralf
  Bokelberg ralf.bokelberg@
  wrote:
  
   Ah sorry, i haven't read the text ;)
   What if you try it like that:
  
   var selectedIndex : int = 0;
   for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
   if( employeeStateId == stateCB.dataProvider[i].stateId ) {
   selectedIndex = employeeStateId ;
   }
   }
   stateCB.selectedIndex = selectedIndex;
  
   Cheers,
   Ralf.
  
   --
   Ralf Bokelberg ralf.bokelberg@
   Flex  Flash Consultant based in Cologne/Germany
   Phone +49 (0) 221 530 15 35
  
 
 
 



 --
 Ralf Bokelberg [EMAIL PROTECTED]
 Flex  Flash Consultant based in Cologne/Germany
 Phone +49 (0) 221 530 15 35

 





--
Ralf Bokelberg [EMAIL PROTECTED]
Flex  Flash Consultant based in Cologne/Germany
Phone +49 (0) 221 530 15 35


[flexcoders] Re: Can't find bug in this piece of ActionScript

2007-02-02 Thread Doug Lowder

Hi,

The bug is that you are continuing through the loop even after you have
found the employeeStateId you are looking for.  What you really want is
something like:

   ...
   if( employeeStateId == stateCB.dataProvider[i].stateId ) {
   stateCB.selectedIndex = employeeStateId ;
   return;
   }
   ...

Also, your code is a little inefficient in that it sets the
selectedIndex to 0 for every item that is *not* the value you are
looking for, instead of setting it to 0 once if the value is not found.

HTH,

Doug


--- In flexcoders@yahoogroups.com, malik_robinson [EMAIL PROTECTED]
wrote:


 Hi,

 I am trying to set the selectedIndex of my U.S. States custom combo
 box equal to what the user has stored in their record in our database.
 Someone posted a link to a similar tutorial, but I could not get it to
 work and I think it seems to be slightly different than what I am
doing.
 When the screen loads, the state the user is associated with should be
 selected, otherwise set the selectedIndex equal to 0.

 As of now it does not select anything it seems the condition where I
 test for equality fails and I always get the selectedIndex set to 0.

 The code:

 public function initStateCB(employeeStateId:Number):void {


 for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
 if( employeeStateId == stateCB.dataProvider[i].stateId ) {
 stateCB.selectedIndex = employeeStateId ;
 }
 else {
 stateCB.selectedIndex = 0;
 }
 }

 } // close function



 mx:FormItem label=State:
 comp:StateCombo id=stateCB dataProvider={model.stateList}
 labelField=stateName

creationComplete=initStateCB(model.employeeProfileArray[0].stateId)/
 /mx:FormItem





[flexcoders] Re: Can't find bug in this piece of ActionScript

2007-02-02 Thread malik_robinson
Hi,

Thanks for all the help.  It works now.  The latest snippet you provided
did the trick. Its nice when it works... Thanks Ralf!

Thanks for your post too Doug.

-Malik

--- In flexcoders@yahoogroups.com, Ralf Bokelberg [EMAIL PROTECTED]
wrote:

 Ok, i understand. Ty it like that:

 public function getStateIndex( employeeStateId : Number, dataProvider
:
 Array) : int {
var selectedIndex : int = 0;
for ( var i:int=0; i dataProvider.length; i++ ) {
if( employeeStateId == dataProvider[i].stateId ) {
   selectedIndex = employeeStateId;
}
 }
 return selectedIndex;
 }

 comp:StateCombo id=stateCB selectedIndex={ getStateIndex(
 model.employeeProfileArray[0].stateId, model.stateList ) }
dataProvider={
 model.stateList}  labelField=stateName/

 Cheers,
 Ralf.

 On 2/2/07, malik_robinson [EMAIL PROTECTED] wrote:
 
Hi,
 
  I am new to actionscript and not quite sure how to implement that
solution
  you suggested.  It looks like the way to go because I do want to
always have
  the right state selected when the detail screen first loads so I
presume
  that is where the binding kicks in.
 
  Here is what I did in the code which I think is wrong how I am
referencing
  the array in the parameter
 
  public function getStateIndex(employeeStateId:Number,
  model.employeeProfileArray[0]:Array):void {
 var selectedIndex : int = 0;
 for ( var i:int=0; i stateCB.dataProvider.length;
i++ ) {
 if( getStateIndex(employeeStateId:==
  stateCB.dataProvider[i].stateId ) {
selectedIndex = getStateIndex(employeeStateId:;
 }
  }
  stateCB.selectedIndex = selectedIndex;
 
  comp:StateCombo id=stateCB selectedIndex={ getStateIndex(
  employeeStateId:Number, model.employeeProfileArray[0]:Array ) }
  dataProvider={model.stateList}  labelField=stateName/
 
  I am using Cairngorm 2.1 and it is actually working pretty well for
me, so
  is there a way to elegantly bind this to the ModelLocator? The array
is
  bound to the ModelLocator
 
 
  --- In flexcoders@yahoogroups.com, Ralf Bokelberg ralf.bokelberg@
  wrote:
  
   That's probably because the creationComplete event is called just
once.
   What if you use binding instead?
  
   selectedIndex={ getStateIndex( *employeeStateId:Number,
  dataProvider:Array*) }
  
   Cheers,
   Ralf.
  
  
  
   On 2/2/07, malik_robinson Malik_Robinson@ wrote:
   
   
Hi,
   
The code works the first time around. First time around meaning
click
an employee from the datagrid and the screen changes to a detail
view
  of
that employee.
   
For some reason every user I bring up after the first user has
the
  same
State (Arizona) for example selected thereafter. The first
time
around it works, but then when I go back to the employee list
screen,
and click a different employee, the detail form populates with
all the
right info like (firstName, lastName, email, city, zip), but the
state
drop down has the value of the state the other user is
associated with
(Arizona).
   
Its as if the code runs correctly once but when you click a
different
user the approriate state does not load, it just has the value
from
  the
prior user. Almost as if once the code runs once, and its being
cached
or something. All the other fields load correctly as I view each
users
detail view.
   
I hope I am making sense.
   
-M
--- In flexcoders@yahoogroups.com
flexcoders%40yahoogroups.com,
  Ralf
Bokelberg ralf.bokelberg@
wrote:

 Ah sorry, i haven't read the text ;)
 What if you try it like that:

 var selectedIndex : int = 0;
 for ( var i:int=0; i stateCB.dataProvider.length; i++ ) {
 if( employeeStateId == stateCB.dataProvider[i].stateId ) {
 selectedIndex = employeeStateId ;
 }
 }
 stateCB.selectedIndex = selectedIndex;

 Cheers,
 Ralf.

 --
 Ralf Bokelberg ralf.bokelberg@
 Flex  Flash Consultant based in Cologne/Germany
 Phone +49 (0) 221 530 15 35

   
   
   
  
  
  
   --
   Ralf Bokelberg ralf.bokelberg@
   Flex  Flash Consultant based in Cologne/Germany
   Phone +49 (0) 221 530 15 35
  
 
 



 --
 Ralf Bokelberg [EMAIL PROTECTED]
 Flex  Flash Consultant based in Cologne/Germany
 Phone +49 (0) 221 530 15 35