Adobe Dreamweaver Forums



Last 10 THreads :         Renaming a project (Last Post : poverbo - Replies : 8 - Views : 15 )           »          Merged Projects Not Appearing in WebHelp TOC (Last Post : hermi14 - Replies : 4 - Views : 5 )           »          Sound.position (Last Post : kglad - Replies : 1 - Views : 2 )           »          Flash-PHP Mail Form (Last Post : kglad - Replies : 1 - Views : 2 )           »          Flash Controls Not Displaying in Embedded File (Last Post : kglad - Replies : 1 - Views : 2 )           »          Making a photo with rounded corners (Last Post : quality11 - Replies : 2 - Views : 3 )           »          Cookies and cflogin (Last Post : idesdema - Replies : 10 - Views : 11 )           »          DW Flash Encoder (Last Post : Hunter Elliott - Replies : 1 - Views : 2 )           »          DIV in Table not working. (Last Post : JoeyD1978 - Replies : 7 - Views : 8 )           »          Web Services (Last Post : DEnglsih - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags: , ,



Reply
  #1 (permalink)  
Old 08-25-2008, 11:47 PM
istrasci
 
Posts: n/a
Diggs:
Default Programatically access a RadioButtonGroup

I know you can call "getChildByName(name)" to access a component (any subclass
of DisplayObject) through it's name property. However,
RadioButtonGroups are not a subclass of DisplayObject, so how can I
programatically get access to them (specifically, so I can clear all buttons
(so none are yet chosen, like at startup).



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-26-2008, 05:21 AM
Ratsnackbar
 
Posts: n/a
Diggs:
Default Re: Programatically access a RadioButtonGroup

You can simply set the groups selection parameter to null.
I took the code for the example from Adobe's Flex Documentation and simply
modified it with a button to clear the group.

<?xml version="1.0"?>
<!-- controls\button\RBGroupEvent.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
<![CDATA[

import mx.controls.Alert;
import mx.events.ItemClickEvent;

private function handleCard(event:ItemClickEvent):void {
if (event.currentTarget.selectedValue == "AmEx") {
Alert.show("You selected American Express.");
} else if (event.currentTarget.selectedValue == "MC") {
Alert.show("You selected MasterCard.");
} else {
Alert.show("You selected Visa.");
}
}

private function clearRadioGroup(event:Event):void{
this.cardtype.selection = null;
}
]]>
</mx:Script>

<mx:RadioButtonGroup id="cardtype" itemClick="handleCard(event);"/>
<mx:RadioButton groupName="cardtype"
id="americanExpress"
value="AmEx"
label="American Express"
width="150"/>
<mx:RadioButton groupName="cardtype"
id="masterCard"
value="MC"
label="MasterCard"
width="150"/>
<mx:RadioButton groupName="cardtype"
id="visa"
value="Visa"
label="Visa"
width="150"/>
<mx:Button id="clearGroup" label="Clear Group"
click="clearRadioGroup(event)"/>
</mx:Application>

Reply With Quote
  #3 (permalink)  
Old 08-26-2008, 04:52 PM
istrasci
 
Posts: n/a
Diggs:
Default Re: Programatically access a RadioButtonGroup

You don't understand what I'm saying... I know how to reset the selection by
setting it to null... What I'm asking is how to get access to the
RadioButtonGroup component programatically... I have a string with the
RadioButtonGroup id... Now give me that component... Like this:

private function(name:String):void
{
// a:RadioButtonGroup = give me the RBG whose id is "name"
a.selection = null
}

If I needed access to a component, I can use getChildByName:

private function(name:String):void
{
a:Label = getChildByName(name) as Label;
a.text = "New label text";
}

But you can't use getChildByName for a RadioButtonGroup... So what do I use
instead, or how can I get the application to return the RBG to me so I can use
it...?


Reply With Quote


  #4 (permalink)  
Old 08-27-2008, 06:26 AM
Ratsnackbar
 
Posts: n/a
Diggs:
Default Re: Programatically access a RadioButtonGroup

Ah I see what you mean. At least I think I do.
Try this instead.
This is basically the same code as before but notice how I use
this[MY_RADIO_GROUP] in the trace statement to obtain a reference to the
object.

The only thing I do not like about this is you cannot bind the ID param of the
radiobuttongroup to the value of the constant (or variable if you wish).
Perhaps there is a way to do that in MXML but if I need to set that value to a
variable I tend to do it in ActionScript and not in MXML. You CAN however set
the value of the RadioButton.groupName parameters with a Binding if you wish
which can come in handy when dynamically generating a radiobutton that can
change to a different group based on need.

So heres the code. Hope this is what you wanted.

<?xml version="1.0"?>
<!-- controls\button\RBGroupEvent.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
<![CDATA[
import mx.utils.ObjectUtil;

import mx.controls.Alert;
import mx.events.ItemClickEvent;

static const MY_RADIO_GROUP:String = "myRadioGroup";

private function handleCard(event:ItemClickEvent):void {
trace(mx.utils.ObjectUtil.toString(this[MY_RADIO_GROUP]));
if (event.currentTarget.selectedValue == "AmEx") {
Alert.show("You selected American Express.");
} else if (event.currentTarget.selectedValue == "MC") {
Alert.show("You selected MasterCard.");
} else {
Alert.show("You selected Visa.");
}
}

private function clearRadioGroup(event:Event):void{
this[MY_RADIO_GROUP].selection = null;
}
]]>
</mx:Script>

<mx:RadioButtonGroup id="myRadioGroup" itemClick="handleCard(event);"/>
<mx:RadioButton groupName="{MY_RADIO_GROUP}"
id="americanExpress"
value="AmEx"
label="American Express"
width="150"/>
<mx:RadioButton groupName="{MY_RADIO_GROUP}"
id="masterCard"
value="MC"
label="MasterCard"
width="150"/>
<mx:RadioButton groupName="{MY_RADIO_GROUP}"
id="visa"
value="Visa"
label="Visa"
width="150"/>
<mx:Button id="clearGroup" label="Clear Group"
click="clearRadioGroup(event)"/>
</mx:Application>

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 10:16 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk