Since the getItemAt() method of ArrayCollection returns an Object,
splitting the code to store this result in a var of type Object should
have made no difference. I suspect that something else is going on that
you're not telling us about.

 

Are you getting a compile time error or a runtime error? Exactly what
does it say?

 

Also... There is no reason to make objUser an instance variable rather
than a local variable. And the acUser parameter of the blah() method
isn't being used in the method body that you showed.

 

Gordon Smith

Adobe Flex SDK Team

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Scott
Sent: Friday, July 18, 2008 6:49 AM
To: flexcoders@yahoogroups.com
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:arrayCollection): void

{

 

            objUser = GlobalVars.instance.acUser.getItemAt(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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Scott
Sent: Friday, July 18, 2008 8:12 AM
To: flexcoders@yahoogroups.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:ArrayCollection = 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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Peter Witham
Sent: Friday, July 18, 2008 12:02 AM
To: flexcoders@yahoogroups.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] <mailto:[EMAIL PROTECTED]> > wrote:

I'm trying to pull a variable from an arrayCollection which I know is
type String.

 

Here's the code:

 

      public var strEMail:String;

            ...

Private function ... 

{

            strEMail = GlobalVars.instance.acUser.getItemAt(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.evolutiondata.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. 

 

Reply via email to