I recall hearing that Dictionary is not a good choice *unless* you are
using object references as keys.

 

The "associative array" or "hashmap" is probably more efficient with
string keys.

 

I am prepared to be corrected.

 

Tracy

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Ryan Graham
Sent: Thursday, November 06, 2008 3:36 PM
To: [email protected]
Subject: RE: [flexcoders] Re: Get id of dynamic validator

 

Another almost identical option to Fotis' is the Dictionary object. I
like that it uses object references for look-up. A great way to manage
run-time generated components...

 

//"true" parameter is to use weak references in the dictionary, so you
can throw objects away and still have them eligible for GC

var globalValidators:Dictionary = new Dictionary(true);

 

//when creating the validator, add it to the dictionary, with the form
item as its key

//note validateString is the name of your validator instance here

globalValidators[formItem[o]] = validateString;

 

//when you need to find formItem[o]'s validator again, for example in
your UpdateItem FOCUS_OUT handler from your earlier code:

 

private function UpdateItem(event:FocusEvent):void

{

    //get validator reference

    var sv:StringValidator = globalValidators[event.target] as
StringValidator;

    ...

}

 

HTH,

Ryan

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of timgerr
Sent: Thursday, November 06, 2008 8:44 AM
To: [email protected]
Subject: [flexcoders] Re: Get id of dynamic validator

No I am again lost. Sorry for the confusion, but I might need a code
example,
globalValidators["validatorID_" + formItem[0].id] = validateString ;
What is an example of validateString . 

Thanks for the help, I am trying to learn a more advanced way to doing
things. 

Thanks again,
timgerr

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Fotis Chatzinikos"
<[EMAIL PROTECTED]> wrote:
>
> Hi timgerr,
> 
> try the following:
> 
> var globalValidators:Object = new Object() ;
> 
> inside the dynamically validators function do the following:
> 
> globalValidators["validatorID_" + formItem[0].id] = validateString ;
> 
> now when you need the validator (and you know the component (and its
id) you
> can get the validator:
> 
> StringValidator sv = globalValidators["validatorID_" +
knownFormItem.id] as
> StringValidator
> 
> 
> On Thu, Nov 6, 2008 at 6:38 AM, timgerr <[EMAIL PROTECTED]> wrote:
> 
> > Not sure how to do that. If the validators are created dynamically:
> >
> > var c:UIComponent = formItem[0];
> > c.addEventListener(FocusEvent.FOCUS_OUT,UpdateItem);
> > var validateString:StringValidator = new
> > StringValidator();
> > validateString.source = c;
> > validateString.property = "text";
> > validateString.required = formItem[0].parent.required;
> > validateString.maxLength = formItem[0].maxChars - 10;
> >
> > How do I make an an associative array? Not sure what the id of the
> > validator is.
> >
> > Thanks for the help,
> > timgerr
> >
> > FYI, c is a UIComponent
> >
> >
> > --- In [email protected]
<mailto:flexcoders%40yahoogroups.com>  <flexcoders%40yahoogroups.com>,
"Tracy
> > Spratt" <tspratt@> wrote:
> > >
> > > Perhaps create an associative array of references to the
validators?
> > >
> > > Tracy
> > >
> > >
> > >
> > > ________________________________
> > >
> > > From: [email protected]
<mailto:flexcoders%40yahoogroups.com>  <flexcoders%40yahoogroups.com>
[mailto:
> > [email protected] <mailto:flexcoders%40yahoogroups.com>
<flexcoders%40yahoogroups.com>] On
> > > Behalf Of timgerr
> > > Sent: Wednesday, November 05, 2008 7:12 PM
> > > To: [email protected]
<mailto:flexcoders%40yahoogroups.com>  <flexcoders%40yahoogroups.com>
> > > Subject: [flexcoders] Get id of dynamic validator
> > >
> > >
> > >
> > > Hello, I have this form and I am createin dynamic validators for
each
> > > textinput. I cannot see how to get the validators id when I try
and
> > > validate the textinput boxes, here is my code:
> > > <mx:Form width="370" id="userInfoForm">
> > > <mx:FormItem label="First Name" required="true"
> > > id="fname_25_string">
> > > <mx:TextInput id="firstName" toolTip="First Name: Max Length 25
> > > Characters"
> > > maxChars="35" text="James"/>
> > > </mx:FormItem>
> > > <mx:FormItem label="Last Name" required="true"
id="lname_25_string">
> > > <mx:TextInput id="lastName" toolTip="Last Name: Max Length 25
> > > Characters"
> > > maxChars="35"/>
> > > </mx:FormItem>
> > > <mx:FormItem label="Email" required="true" id="Email__">
> > > <mx:TextInput id="email" editable="false" toolTip="Cannot edit
> > > this field"/>
> > > </mx:FormItem>
> > > <mx:FormItem label="Title" id="tit_25_string">
> > > <mx:TextInput id="title" maxChars="35" toolTip="Title: Max
> > > Length 25 Characters"/>
> > > </mx:FormItem>
> > > </mx:Form>
> > >
> > > So I do a creationcomplete to run a function to get a list of
all the
> > > textboxes:
> > > private function GetChild(item:Object):void
> > > {
> > > var formItems:Array = item.getChildren();
> > > // loop items and add values
> > > for (var i:int = 0; i < formItems.length; i++)
> > > {
> > > // formItem
> > > var formItem:Array = formItems[i].getChildren();
> > > var c:UIComponent = formItem[0];
> > > if(c.className.toString() == 'TextInput'){
> > > var rtnID:String = c.id;
> > > formItem[0].text = _performaReturnUsersData[rtnID];
> > > /* adding an eventlistener (focuseEvent) to all textinput
> > > */
> > > c.addEventListener(FocusEvent.FOCUS_OUT,UpdateItem);
> > > var validateString:StringValidator = new
> > > StringValidator();
> > > validateString.source = c;
> > > validateString.property = "text";
> > > validateString.required = formItem[0].parent.required;
> > > validateString.maxLength = formItem[0].maxChars - 10;
> > > }
> > > }
> > > }
> > >
> > > This function will go through an find textinput boxes then assign
a
> > > validator to them. So all is working but the problem is I have no
> > > idea how to validate the data without knowing the id of the
individual
> > > instance of the validator.
> > >
> > > I have added a listener to the instances of the textinput called
> > > UpdateItem, so here is the code:
> > >
> > > function UpdateItem(f:FocuseOut):void
> > > {
> > > trace(f.target.id);
> > > // Not sure what to do here becuase I dont know the id of the
> > > validator attached to the textinput
> > > }
> > >
> > > How can I see if the textinput passes the validators?
> > >
> > > Thanks for the help,
> > > timgerr
> > >
> >
> > 
> >
> 
> 
> 
> -- 
> Fotis Chatzinikos, Ph.D.
> Founder,
> Phinnovation
> [EMAIL PROTECTED],
>

This message is private and confidential. If you have received it in
error, please notify the sender and remove it from your system.

 

Reply via email to