Question

I have to use a lot of Point constructors, like so :

function setLoc(o:*, loc:Point):void
{
    o.x = loc.x;
    o.y = loc.y;
}

setLoc(obj1, new Point(25,50));
setLoc(obj2, new Point(13,-5));
setLoc(obj3, new Point(186.5,-23));
...

Is there a way to write these in a more compact way, maybe some macros or compiler tricks ? It is very tedious to have to write "new Point(...)" for such a simple Class. I wish I could do something like :

setLoc(obj1, (25,50));

(I dont want to change setLoc(o,p) to setLoc(o,px,py) but I guess thats the best solution)

Was it helpful?

Solution

You could do this:

setLoc(obj1, {x:25, y:50});

Just change the type of the loc argument to Object:

function setLoc(o:*, loc:Object):void
{
    o.x = loc.x;
    o.y = loc.y;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top