You can use an Object to store name/value pairs for your created
components, rather than an Array. For example, if you do
// Any other method in this class can access the radio buttons using
this Object.
private var radioButtons:Object = {};
private function createRadioButtons():void
{
for (var i:int = 0; i < ...; i++)
{
var rb:RadioButton = new RadioButton();
// set properties, styles, and event handlers on rb
radioButtons[radioButtonNames[i]] = rb;
}
}
you can later access them as radioButtons["myButton"] (or
radioButtons.myButton), etc.
- Gordon
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of alex steel
Sent: Tuesday, April 10, 2007 12:20 AM
To: [email protected]
Subject: [flexcoders] Re: dynamically created access and event elements
problem and
Thanks again :)
I understand referencing by array,
but isn't it possible to reference by dynamiclly created name
like in flash you can use name to create movieclip
_root.createEmptyMovieClip("name", 1000)
and then
name or _root["name"] can be use as reference
another question is
how I can pass variable via event
basiclly if I have array of elements then I would like to pass array
position of element in array so I can determine if it's left or right
checkbox so I can keep only one of two checkboxes selected
if I could add variables to elements that would be good
like I can do in flash with movieclips mc.number = i
or that need extending checkbox class ?
thanks in advance
--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Gordon Smith" <[EMAIL PROTECTED]> wrote:
>
> Sorry... in the second example,
>
> var rb:RadioButton;
>
> should be
>
> var rb:RadioButton = new RadioButton();
>
> - Gordon
>
> ________________________________
>
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of Gordon Smith
> Sent: Thursday, April 05, 2007 1:17 PM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com>
> Subject: RE: [flexcoders] Re: dynamically created access and event
> elements problem and
>
>
>
> > can you help me on part "you should keep variable referencing to
> checkboxes"
>
> Define an instance variable in your app or component. When you
> dynamically create a CheckBox, store it in that variable:
>
> <mx:Script>
>
> // Any other method in this class can access the radio buttons using
> these variables
> private var radioButton1:RadioButton;
> private var radioButton2::RadioButton;
>
> private function createRadioButtons():void
> {
> radioButton1 = new RadioButton();
> // set properties, styles, and event handlers on radioButton1
>
> radioButton2 = new RadioButton();
> // set properties, styles, and event handlers on radioButton1
> }
>
> </mx:Script>
>
> If you don't know in advance how many checkboxes you''ll be creating,
> use an array:
>
> <mx:Script>
>
> // Any other method in this class can access the radio buttons using
> this array.
> private var radioButtons:Array /* of RadioButton */ = [];
>
> private function createRadioButtons():void
> {
> for (var i:int = 0; i < ...; i++)
> {
> var rb:RadioButton;
> // set properties, styles, and event handlers on rb
> radioButtons.push(rb);
> }
> }
>
> </mx:Script>
>
> - Gordon
>
> ________________________________
>
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of alex steel
> Sent: Thursday, April 05, 2007 5:19 AM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com>
> Subject: [flexcoders] Re: dynamically created access and event
elements
> problem and
>
>
>