I’m trying to set 2 object each with different data, and pass it into another function as parameters, but when I trace for the data in the object, I can only get the 2nd object data. Seems like the 1st object was replaced by the 2nd object.
TimeSpan.betweenMonths(MyDate.setDate(1984), MyDate.setDate(1988))
The Date Object:
package hwang.time
{
public class MyDate
{
private static var _year:Number;
public static function setDate(year:Number):MyDate
{
_year = year;
return new MyDate
}
public function get year():Number
{
return _year
}
}
}
The Class the object was pass into:
public static function betweenMonths(myDate1:MyDate, myDate2:MyDate):int
{
yearArray = [myDate1, myDate2]
trace(yearArray[0].year, yearArray[1].year) // both returnng 1988
}
I’m not quite sure to understand the need for a static function as opposed to using a constructor!