There are several ways to do this.  The simplest to code is to directly
access your control by dottting down through the component dom.  If your
component is directly referenced by id in the main app you can do:
myCompId.chkBox1.selected.

 

This might not be the best term solution, though, depending on how many
such references you will have and how flexible and reusable you want
your component to be.

 

The most "loosely coupled" design would be to have your component
dispatch a custom event when a control is interacted with, and listen
for that event in the parent.  Extending the Event object will let you
include any data you want in the event, such as the states and values of
the controls.

 

Between those extremes are other options, such as passing references to
the main app into the component, which can then update a data
structure(like an array or associative array) in the main app.

 

As I said there are lots of options.  Its ok to take the simple code
path to start with.  Just keep in mind  longer term best practices.

 

Tracy

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Lisa Lee
Sent: Tuesday, December 26, 2006 7:43 PM
To: [email protected]
Subject: [flexcoders] How to Use the Value of a Checkbox in a Component

 

Hello, I'm very new to Flex so please excuse my "newbie" question if it 
seems a bit dumb...but here is my situation: I have a Flex 
application - let's call the main application file 'Main.mxml' - I have 
a component file - let's call it 'MyComp.mxml'. Within 
the 'MyComp.mxml' file I have an <mx:CheckBox id="chkBox1"> object. I 
am calling the MyComp component from the Main.mxml file. The user can 
check or uncheck this checkbox and then click on a 'Submit' button that 
is defined in the Main.mxml file, which will then fire off the 
processing logic. All I want to do in the processing logic is to be 
able to examine whether the user has checked the chkBox1 checkbox or 
not, so that I can pass that value from the Main.mxml file to a web 
service. But when I try to do a simple binding {chkBox1.selected} from 
within the Main.mxml file, the error I get is '1120: Access of 
undefined property chkBox1.' Can anyone help?

 

Reply via email to