Is there any way to create typed objects in AS3? I have had issues with non typed objects causing errors because of NaN and null I think…
Eg…
var myObject:Object.<int> = new Object.<int>();
myObject.Row = 22;
myObject.Col = "14"; // Converts to number or NaN/Null, etc... Something that won't cause an error.
etc...
Both of these functions do the exact same thing in a optimal scenario, but the first causes errors when the rowCol.Row and rowCol.Col variables are non numeric.
//This function has errors with bad rowCol inputs
public static function rowColToPoint(rowCol:Object, tileSizeX:int, tileSizeY:int):Point {
var xyPoint = new Point();
xyPoint.x = (rowCol.Col - rowCol.Row) * ((tileSizeX / 2) + 1);
xyPoint.y = (rowCol.Col + rowCol.Row) * (tileSizeY / 2);
return xyPoint;
}
//This function is stable and error free
public static function rowColToPoint(rowCol:Object, tileSizeX:int, tileSizeY:int):Point {
var xyPoint = new Point();
xyPoint.x = (int(rowCol.Col) - int(rowCol.Row)) * ((tileSizeX / 2) + 1);
xyPoint.y = (int(rowCol.Col) + int(rowCol.Row)) * (tileSizeY / 2);
return xyPoint;
}
//This function is stable and error free and the one I use
public static function rowColToPoint(rowCol:Object, tileSizeX:int, tileSizeY:int):Point {
var rowIn:int = rowCol.Row;
var colIn:int = rowCol.Col;
var xyPoint = new Point();
xyPoint.x = (colIn - rowIn) * ((tileSizeX / 2) + 1);
xyPoint.y = (colIn + rowIn) * (tileSizeY / 2);
return xyPoint;
}