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?