You could add a convenience method that tries to parse the resulting string from the getFlashVar
function as a Date object. It returns a Date
object if the input string could be parsed to a date and otherwise returns undefined
.
public static function parseDateFromString(value:String):Date {
var dateObject:Number = Date.parse(value);
if (isNaN(dateObject)) {
return undefined;
}
return new Date(dateObject);
}
To use it, pass the returning value from getFlashVar
to parseDateFromString
like this:
var beginLive:Date = parseDateFromString(getFlashVar('beginLive', "undefined"));
var endLive:Date = parseDateFromString(getFlashVar('endLive', "undefined"));
Example output:
trace(parseDateFromString("01/30/2014")); // Thu Jan 30 00:00:00 GMT+0100 2014 (Date object)
trace(parseDateFromString("undefined")); // null (actually undefined)