Josh
Okay, so here's what I did... var person : Person = new Person(); person.wakeup
= new Date();person.breakfast = new Date();person.lunch = new
Date();person.dinner = null;person.bedtime = null; var wfArr : Array = new
Array(); timeArr[0] = "wakeup";timeArr[1] = "breakfast";timeArr[2] =
"lunch";timeArr[3] = "dinner";timeArr[4] = "bedtime"; var event : int;if (some
criteria) { event = 2; } if (some criteria) {
person[timeArr[event]] = null; }and it works... person.lunch... aka
person["lunch"]... was set to null... thanks, you rock!! Darren
To: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Thu, 17 Jul 2008 12:18:35
+1000Subject: Re: [flexcoders] Array reference vs values
On Thu, Jul 17, 2008 at 11:55 AM, Darren Houle <[EMAIL PROTECTED]> wrote:
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?DarrenI think so. But you're definitely going about it the wrong way -
hear me out:In ECMAScript, you can access any public field by indexing its name
as a string. Now assuming person has these fields, and you want to be able to
access them (and mess with them) in order. There's a few ways to do this:const
fieldOrder : Array = [ 'wakeup', 'breakfast', 'lunch', 'dinner',
'bedtime', ];Then you can do this:trace(myPerson.lunch); // ==
date.toString()myPerson[fieldOrder[2]] = null;trace(myPerson.lunch); // ==
nullBut while you can mute that instance of date, you can't delete it. It
defeats the purpose of garbage collection (and probably makes it a lot harder
to implement).If say, myPerson is *dynamic* either by the dynamic keyword on
the class definition, or because it's created with "{}" instead of "new
ClassName()", you can also do thisdelete
myPerson[fieldOrder[2]];trace(myPerson.lunch); // === undefined, or an
exception is thrown depending on various conditions of myPerson :)This will
completely remove the "lunch" field from the myPerson instance, but the Date
instance itself will still be sitting around waiting for garbage
collection.-Josh-- "Therefore, send not to know For whom the bell tolls. It
tolls for thee.":: Josh 'G-Funk' McDonald:: 0437 221 380 :: [EMAIL PROTECTED]