zaterdag 1 januari 2011

as2 to as3

I'm a regular flash-guru according to some. I program games, so if there is a problem in Flash, I usually find it. Up until last year I still programmed in as2 and hadn't done much OOP (Object Oriented Programming)
So I figure, I go learn it in 2011, blog about what I find and maybe make some people happy, who knows.

Now I found out one of the first surprising things quite quickly. Don't think you know something, even when it doesn't seem to have changed.

this is (very concise) as2:
mc.localToGlobal(p={x:0,y:0});

after this p.x and p.y hold the coordinates of mc's anchorpoint on the stage..
I use this a lot in game-development in as2.
I was thrilled that the function hadn't changed..
BUT!
in as3 the above always leaves you with the original point, nothing happens!
in as3 the snippet would be:
var p:Point=new Point(0,0);
p=mc.localToGlobal(p);

As you can see, the difference is subtle. In as2, the point that you give is modified. In as3 the point is returned from the function and the original point is left unaltered.
I know the latter is more correct and I understand now why they did it..
But WHY weren't we warned. I found NO reference to this whatsoever.

Bad Adobe!

Geen opmerkingen:

Een reactie posten