Here is some sturdy logic for grabing some siblings, in any case:
function getSiblings(target:Object):Array {
var i:Number = radioButtons.length, r:Array=[];
while(i--)if(radioButtons[i]!=target)r.push(radioButtons[i]);
return r;
}
More likely, you will be doing something like this in your group class:
var radioButtons:Array;
private var _selectedIndex:Number;
function setSelect(index:Number):Void {
deselect();
_selectedIndex = index;
select();
}
function select():Void {
radioButtons[_selectedIndex].setSelected(true);
}
function deselect():Void {
radioButtons[_selectedIndex].setSelected(false);
}
//and this in your radioButton class
function setSelected(value:Boolean):Void {
this.dotGraphic._visible=value;
}
The amount of functions may seem redundant, but seperating the tasks like
this will give the component a real flexible API. Don't know when you might
need your radio buttons to take the dog for a walk or something, hehe.
M.
On 4/22/06, Julian 'Julik' Tarkhanov <[EMAIL PROTECTED]> wrote:
>
>
> On 21-apr-2006, at 23:49, elibol wrote:
>
> > I think the best way to implement this would be to have a
> > RadioGroup class
> > that would instantiate through static functions of the RadioButton
> > class. A
> > static variable of the RadioGroup class would manage RadioGroup
> > instances,
> > it would add and remove RadioGroup instances through a static API.
> > A static
> > function of the RadioButton would take the RadioButton instances
> > radioGroupID property and check if it exists, if it does it would
> > add the
> > instance to the radio group, if not it would instantiate a new
> > radio group.
> >
> > Each radio button would have an instance of the radio group they
> > belonged
> > to, when they were selected, they would just call a select() style
> > function
> > of their own radio group and submit their index/id to be activated.
> > You
> > should handle activation and deactivation of radio buttons from the
> > radio
> > group class.
> >
> > You should also implement a die() method which derefrences radio
> > buttons
> > from radio groups so that radio group instances are destroyed when
> > they no
> > longer contain any radio buttons.
> >
> > Hope this helps,
>
> Yeo, will try that, I just hoped there is a way to determine the
> siblings at runtime and avoid the whole referencing-dereferencing-
> registration-callbacks thing. Hope that will be possible with AS3.
>
> Attaching callbacks to the group instead of the buttons is a n
> interesting idea though.
>
> --
> Julian 'Julik' Tarkhanov
> please send all personal mail to
> me at julik.nl
>
>
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com