![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
There are several ways to do this.
1) Create an array of CheckBoxes and access with if (fruit[n].selected) 2) Use a repeater to create N checkboxes and access through the repeater. I'm still a beginner with repeaters, so I think it would look something like: <mx:Repeater id="rep" dataSource={some_array_with_N_elements}> <mx:CheckBox .../> </mx:Repeater> Then you'd access with something like: if (rep[n].CheckBox.selected) Actually, I'm positive that's not totally correct, so you'd have to check documentation on how to access with repeaters. 3) Use the getChildByName() method in conjunction with building the string in the Actionscript code like you are doing. But then you'd have to set the "name" property of each checkbox in such a way that they are similar enough to each be constructed using the loop index. Something like this: <mx:CheckBox name="fruit1" .../> <mx:CheckBox name="fruit2" .../> ... Then in the Actionscript code, you'd access with: if (getChildByName("fruit"+n).selected) If you know how to use repeaters, then option 2 is probably the best and most concise. If not, it might be more trouble than it's worth (at least at this point) to learn how to use them, and go with option 1 or 3.. |
| Sponsored Links |
|
|||
|
There are several ways to do this.
1) Create an array of CheckBoxes and access with if (fruit[n].selected) 2) Use a repeater to create N checkboxes and access through the repeater. I'm still a beginner with repeaters, so I think it would look something like: <mx:Repeater id="rep" dataSource={some_array_with_N_elements}> <mx:CheckBox .../> </mx:Repeater> Then you'd access with something like: if (rep[n].CheckBox.selected) Actually, I'm positive that's not totally correct, so you'd have to check documentation on how to access with repeaters. 3) Use the getChildByName() method in conjunction with building the string in the Actionscript code like you are doing. But then you'd have to set the "name" property of each checkbox in such a way that they are similar enough to each be constructed using the loop index. Something like this: <mx:CheckBox name="fruit1" .../> <mx:CheckBox name="fruit2" .../> ... Then in the Actionscript code, you'd access with: if (getChildByName("fruit"+n).selected) If you know how to use repeaters, then option 2 is probably the best and most concise. If not, it might be more trouble than it's worth (at least at this point) to learn how to use them, and go with option 1 or 3.. |
|
|||
|
There are several ways to do this.
1) Create an array of CheckBoxes and access with if (fruit[n].selected) 2) Use a repeater to create N checkboxes and access through the repeater. I'm still a beginner with repeaters, so I think it would look something like: <mx:Repeater id="rep" dataSource={some_array_with_N_elements}> <mx:CheckBox .../> </mx:Repeater> Then you'd access with something like: if (rep[n].CheckBox.selected) Actually, I'm positive that's not totally correct, so you'd have to check documentation on how to access with repeaters. 3) Use the getChildByName() method in conjunction with building the string in the Actionscript code like you are doing. But then you'd have to set the "name" property of each checkbox in such a way that they are similar enough to each be constructed using the loop index. Something like this: <mx:CheckBox name="fruit1" .../> <mx:CheckBox name="fruit2" .../> ... Then in the Actionscript code, you'd access with: if (getChildByName("fruit"+n).selected) If you know how to use repeaters, then option 2 is probably the best and most concise. If not, it might be more trouble than it's worth (at least at this point) to learn how to use them, and go with option 1 or 3.. |
|
|||
|
"miglara" <webforumsuser@macromedia.com> wrote in message news:gbr2u5$r00$1@forums.macromedia.com... > Hi, > > I'm new a Flex and it seems it's more complicated that it should be... but > hopefully I'm wrong. > I'm trying to create a list of 7 fruits, that include a picture, a > checkbox > and its label in English. > There is a Submit button that when it's clicked, the label of the selected > checkboxes changes to Spanish. > I have this partially working but my problem is to loop through all 7 > elements > using a for loop to avoid long lines of code. > I attempted doing it like I would do it in javascript: > > for (i=1; i<8; i++){ > if ( "fruit"+i+".selected") { > } > } > } > > But it's not working. I spent 2 hours surfing in the web but the solutions > are > related to including a datagrid or a list but it seems too difficult and > they > don't mention anything about handling pictures. My code is quite simple, > something like the following 7 times, just changing the image source and > the > fruit index. > > <mx:Image x="479" y="21" source="images/banana.gif" width="50" > height="50"/> > <mx:CheckBox x="554" y="49" label="Banana" id="fruit1" textAlign="left"/> > > Your help will be greatly appreciate it! Flex 3 Training From the Source has an example of exactly this. Actually, I think they have several. |
|
|||
|
"miglara" <webforumsuser@macromedia.com> wrote in message news:gbr2u5$r00$1@forums.macromedia.com... > Hi, > > I'm new a Flex and it seems it's more complicated that it should be... but > hopefully I'm wrong. > I'm trying to create a list of 7 fruits, that include a picture, a > checkbox > and its label in English. > There is a Submit button that when it's clicked, the label of the selected > checkboxes changes to Spanish. > I have this partially working but my problem is to loop through all 7 > elements > using a for loop to avoid long lines of code. > I attempted doing it like I would do it in javascript: > > for (i=1; i<8; i++){ > if ( "fruit"+i+".selected") { > } > } > } > > But it's not working. I spent 2 hours surfing in the web but the solutions > are > related to including a datagrid or a list but it seems too difficult and > they > don't mention anything about handling pictures. My code is quite simple, > something like the following 7 times, just changing the image source and > the > fruit index. > > <mx:Image x="479" y="21" source="images/banana.gif" width="50" > height="50"/> > <mx:CheckBox x="554" y="49" label="Banana" id="fruit1" textAlign="left"/> > > Your help will be greatly appreciate it! Flex 3 Training From the Source has an example of exactly this. Actually, I think they have several. |
|
|||
|
"miglara" <webforumsuser@macromedia.com> wrote in message news:gbr2u5$r00$1@forums.macromedia.com... > Hi, > > I'm new a Flex and it seems it's more complicated that it should be... but > hopefully I'm wrong. > I'm trying to create a list of 7 fruits, that include a picture, a > checkbox > and its label in English. > There is a Submit button that when it's clicked, the label of the selected > checkboxes changes to Spanish. > I have this partially working but my problem is to loop through all 7 > elements > using a for loop to avoid long lines of code. > I attempted doing it like I would do it in javascript: > > for (i=1; i<8; i++){ > if ( "fruit"+i+".selected") { > } > } > } > > But it's not working. I spent 2 hours surfing in the web but the solutions > are > related to including a datagrid or a list but it seems too difficult and > they > don't mention anything about handling pictures. My code is quite simple, > something like the following 7 times, just changing the image source and > the > fruit index. > > <mx:Image x="479" y="21" source="images/banana.gif" width="50" > height="50"/> > <mx:CheckBox x="554" y="49" label="Banana" id="fruit1" textAlign="left"/> > > Your help will be greatly appreciate it! Flex 3 Training From the Source has an example of exactly this. Actually, I think they have several. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise