There is no reason why
strEMail = acUser.getItemAt(0).strEMail; shouldn't both compile and run if the 0th item in the ArrayCollection acUser has a property named strEMail of type String. And, in fact, I had no problem compiling and running var acUser:ArrayCollection = new ArrayCollection([ { strEMail: "foo" } ]); var strEMail:String = acUser.getItemAt(0).strEMail; trace(strEMail); It traced "foo" as one would expect. Since getItemAt()'s return type is Object, the compiler lets you access any property on it. (Of course, strong typing is better practice). And when you access a property on an Object, the compiler treats that property as having type *, which can be assigned to a String var without casting it to a String. Gordon Smith Adobe Flex SDK Team ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Sid Maskit Sent: Friday, July 18, 2008 1:35 PM To: flexcoders@yahoogroups.com Subject: Re: {Disarmed} Re: [flexcoders] Variable Typecasting As someone else explained, it is better to use strongly typed objects then generic ones. However, if you are going to use a generic one, something like the following should work: strEMail = GlobalVars.instance.acUser.getItemAt(0)["strEMail"] as String; Two things to note here. First, if you are using a generic object, you can access its properties using bracket offsets with the property name in quotes. You need to do this since what you actually have is an associative array, and the compiler cannot know what its keys are. Second, the preferred method of casting is not to use a constructor, a la String(whatIAmCasting), but to use the as operator, a la whatIAmCasting as String. ----- Original Message ---- From: Scott <[EMAIL PROTECTED]> To: flexcoders@yahoogroups.com Sent: Friday, July 18, 2008 6:48:58 AM Subject: RE: {Disarmed} Re: [flexcoders] Variable Typecasting Wow. This was incredibly frustrating but after playing around (and rebooting my computer numerous times from the debugger crashing) I finally figured out how to reference the data in the arraycollection. I didn't have to typecast it. However, I had to process it one function at a time. I tried strEMail = String(GlobalVars. instance. acUser.getItemAt (0).strEMail) ; and that didn't work; it kept throwing an error that it didn't know about strEMail. After playing around I discovered that if I broke out the functions it would work. This is what worked for me: private var objUser:Object; private function blah( acUser:arrayCollect ion): void { objUser = GlobalVars.instance .acUser.getItemA t(0); strEMail = String(objUser. strEMail) ; } After I got the results I wanted, I tried it again as one line and Flex threw an error that it again didn't know about strEMail. Perhaps that's a bug...? -sj ________________________________ From: [EMAIL PROTECTED] ups.com [mailto:flexcoders@ yahoogroups. com] On Behalf Of Scott Sent: Friday, July 18, 2008 8:12 AM To: [EMAIL PROTECTED] ups.com Subject: {Disarmed} Re: [flexcoders] Variable Typecasting It seemed to have taken that but now it's still not pulling the data in as I would expect it. The getItemAt(x) in reading looks like it would pull in the whole record at 'x'. However, it won't let me refer to the record as getItemAt(0) .strEMail since it doesn't know strEMail exists in that collection. In structures (in C++/Coldfusion/ etc...) I had to define the variable names within the structure. However, in AS3 I just defined the variable: [Bindable] public var acUser:ArrayCollect ion = new ArrayCollection( ); How do I access the strEMail from the array collection (or at least tell the Flex compiler that the variable really does exist). Thanks sj ________________________________ From: [EMAIL PROTECTED] ups.com [mailto:flexcoders@ yahoogroups. com] On Behalf Of Peter Witham Sent: Friday, July 18, 2008 12:02 AM To: [EMAIL PROTECTED] ups.com Subject: {Disarmed} Re: [flexcoders] Variable Typecasting Have you tried strEMail = String(GlobalVars. instance. acUser.getItemAt (0)); Do not have my machine in front of me to test but pretty sure you can cast something that way. I know that's the way I do it to cast MovieClip names. Regards, Peter On 7/17/08, Scott <[EMAIL PROTECTED] us <mailto:[EMAIL PROTECTED]> > wrote: I'm trying to pull a variable from an arrayCollection which I know is type String. Here's the code: publicvar strEMail:String; ... Private function ... { strEMail = GlobalVars.instance .acUser.getItemA t(0); } That above line of course throws an error because it's not sure that the variable at (0) is actually a string even though I know it is. In C++ I would just tell it using a typecast that it is a string. How can I copy that element into a variable? Thanks! -- Peter Witham http://www.evolutio ndata.com <http://www.evolutiondata.com> Internet and Multimedia developer Certified Flash Designer. -- This message has been scanned for viruses and dangerous content by MailScanner <http://www.mailscanner.info/> , and is believed to be clean. -- This message has been scanned for viruses and dangerous content by MailScanner <http://www.mailscanner.info/> , and is believed to be clean.