I would guess that === is actually faster than == as the latter has to check whether it needs to perform any casting before checking equality. Out of curiousity, have you tried to use "" instead of new String() to initialize category (it's unconventional to use new String() in AS3)? Otherwise, you could send the complete source in a bug for the team to take a look. Pete
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of simonjpalmer Sent: Wednesday, April 04, 2007 12:42 PM To: [email protected] Subject: [flexcoders] Re: question about string equality Good point, I didn't include the declarations. They are both strongly typed Strings, I don't use objects anywhere in my code. co is a custom AS object of type "Competitor", here's the declaration of the name member: public var name:String; oc is a custom AS object of type "ObjectCategory" and here is the declaration of the category member: public var category:String = new String(); The strong typing answers the question about whether they just happen to contain strings. Other than the fact that they belong to custom objects I have written, there is nothing peculiar about either the string variables or their contents. I don't think they are in a custom namespace, but to be honest I'm not exactly sure what that means, so I can't say with certainty that they aren't. I think the answer is no. co.name gets populated by various means, either though a user gesture in a custom page or by retrieval from a java data adaptor to my server. oc.category is populated programmatically during execution of the code in question. I appreciate you guys looking at this. Right now I have it working as I expect but it is a bit worrying that I need to do the comparison in this way only in this instance. That says to me that I don't properly understand something. If I want to check equality of the content of two strings should I always be testing valueOf()? What is the overhead of using ===? --- In [email protected] <mailto:flexcoders%40yahoogroups.com> , "Peter Farland" <[EMAIL PROTECTED]> wrote: > > What are the type declarations of the properties sc.name and > sc.category? Do they just happen to hold String values or are they typed > to enforce that they hold String values? Is there anything else unique > about these properties? Are they in a custom namespace? Are they > read-only? How were they populated in the first place? > > ________________________________ > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of simonjpalmer > Sent: Monday, April 02, 2007 6:14 PM > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] question about string equality > > > > take a look at this code snippet... > > 01 // check one doesn't already exist with this name > 02 bFound = false; > 03 for (isc = 0; isc < ss.scenarios.length && !bFound; isc++) > 04 { > 05 sc = Scenario(ss.scenarios.getItemAt(isc)); > 06 if (sc.name.valueOf() == oc.category.valueOf()) bFound = true; > 07 } > 08 if (!bFound) > 09 { > 10 // Make a new scenario > 11 sc = PlanPointFactory.makeScenario(uli, null, true, false); > 12 > 13 // add it to the snapshot > 14 ss.addScenario(sc); > 15 > 16 // add it to the local array of categories > 17 oc.objects.push(sc); > 18 } > > line 06 is the offending line. > > if I have: > > 06 if (sc.name == oc.category) bFound = true; > > the bFound flag never gets set true. I have to have the valueOf() > function in order for the equality to fire correctly. > > This is not what I expected. I thought that regular equality would > have sufficed here since sc.name and oc.category are both Strings. > > Why am I wrong and why do I need valueOf()? >

