I think this has been explained several times already in this thread, but you don't seem to have understood so I'll try explaining with some ASCII art. Before assigning timeArr[2] = null you have
person.lunch --------> <a Date instance> ^ | timeArr[2] ------------------- After assigning timeArr[2] = null you have person.lunch --------> <a Date instance> timeArr[2] --> <nothing> You are not nulling the Date instance. (I don't even know what that would mean.) You are nulling the 2nd element in the timeArr Array which referred to the Date instance. Basically, AS reference are like C++ pointers, not like C++ references. If you are trying to represent a sequence of times, don't use five vars in Person named wakeup, breakfast, lunch, dinner, and bedtime. Use a single Array with five elements var times:Array /* of Date /; and use the constants static const WAKEUP:int = 0; static const BREAKFAST:int = 1; static const LUNCH:int = 2; static const DINNER:int = 3; static const BEDTIME:int = 4; to access them as times[LUNCH], etc. Gordon Smith Adobe Flex SDK Team ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Darren Houle Sent: Wednesday, July 16, 2008 6:56 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Array reference vs values Josh Yes, what you're describing is exactly what I described and is, in fact, what it happening... but to say I don't ever need to do this? Well... yes... I need to do this... and it has nothing to do with the garbage collector. Here, let me explain in another way.... I have a custom object... lets say it's a Person object. It has various properties, but several are Date types. These are all consecutive, like a workflow, and I want to be able to address them in order via an array... like this... var person : Person = new Person(); person.wakeup = new Date(); person.breakfast = new Date(); person.lunch = new Date(); person.dinner = null; person.bedtime = null; var timeArr : Array = new Array(); timeArr[0] = person.wakeup; timeArr[1] = person.breakfast; timeArr[2] = person.lunch; timeArr[3] = person.dinner; timeArr[4] = person.bedtime; Then some other code figures out where we are in the flow of the day's events... var status : int; if (some criteria) { event = 2; } But I determine lunch hasn't actually happened yet, so it shouldn't have a Date yet. I need to blank out this value that was previously set in the Person object... if (some criteria) { timeArr[event] = null; } But since these references don't seem to propogate backwards, nulling one of the array elements doesn't affect the original property. That's the *whole purpose* of reference vs value... a reference is a pointer to memory space... so if I null that memory space it should affect all the vars pointing to that memory space. Does that make more sense? Darren ________________________________ To: flexcoders@yahoogroups.com From: [EMAIL PROTECTED] Date: Thu, 17 Jul 2008 11:30:29 +1000 Subject: Re: [flexcoders] Array reference vs values When you do this: var date:Date = new Date(); You're creating an instance of Date and a reference to it named "date". When you do this: var ref:Date = arr[0] as Date; You're creating another reference to the same instance, this time your reference is named "ref". So when you set ref = null, you're making "ref" point to nothing. "date" and "arr[0]" remain unchanged. You don't need to, nor can you remove the date instance created above. That's the job of the garbage collector. -Josh On Thu, Jul 17, 2008 at 11:25 AM, Darren Houle <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: This might be a basic AS question, but I encountered it building a Flex app, so... I create a Date var date:Date = new Date(); I create an Array var arr:Array = new Array(); I set the first element of the array equal to the date arr[0] = date; I create another date variable that refers to the first array element var ref:Date = arr[0] as Date; if I trace("date="+date+", arr[0]="+arr[0]+", ref="+ref) I get date=Wed Jul 16 21:04:45 GMT-0400 2008, arr[0]=Wed Jul 16 21:04:45 GMT-0400 2008, ref=Wed Jul 16 21:04:45 GMT-0400 2008 Now I null out the ref variable ref=null; Since AS uses references instead of values I would expect to null out the original date, but no... If I trace("date="+date+", arr[0]="+arr[0]+", ref="+ref) I now get date=Wed Jul 16 21:04:45 GMT-0400 2008, arr[0]=Wed Jul 16 21:04:45 GMT-0400 2008, ref=null I thought everything was a reference in AS? Shouldn't nulling ref also null arr[0] which would null out date? Ultimately... I have a custom object that has several fields each containing a Date. I create an array and make each element in the array = each Date in the custom obj. I need to be able to null an array element and have it carry backwards into the object and null out the original Date. Any ideas? Am I missing something really obvious? ------------------------------------ -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt <http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> Search Archiv! es: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo <http://www.mail-archive.com/[EMAIL PROTECTED] 0aoo> ! Groups Links (Yahoo! ID required) mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> -- "Therefore, send not to know For whom the bell tolls. It tolls for thee." :: Josh 'G-Funk' McDonald :: 0437 221 380 :: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>