I am stuck in as3 hit test problem. this is the code i wrote in as2. please help me migrate this in to as3
target.hitTest((_x - _width / 2) * (1 / (100 / _root.game._xscale)) + _root.game._x,
_y * (1 / 开发者_Python百科(100 / _root.game._yscale)) + _root.game._y, true)
_root, _levelX, etc do exist in AS3. You would need to replace _root with the reference of object that contains "game" object. If "game" object is at stage level, you can use game.stage.prop/meth, for most of things.
Another important thing, _xscale/_yscale accepted percentages as 1 to 100 and so on, whereas scaleX and scaleY accept 0 to 1, and so on.
target.hitTestPoint ((x - width/2) * (1/rootApp.scaleX) + rootApp.game.x, y * (1/rootApp.game.scaleY) + rootApp.game.y, true);
Where "rootApp" is reference to the object, that holds the "game" displayobject (movieclip, sprite or other).
Hope that helps.
-abdul
In AS3 many variables had your name changed. Did you declared the variables _x, _width, _root, _xscale, _y and _yscale?
If not, then this is your problem, all you got to do is change these for the right new variables: x, width, root (stage would be better), scaleX, y and scaleY.
Also, there is no longer hitTest method, instead, you should use hitTestObject or hitTestPoint.
You should also take a look at this url: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/migration.html
Cheers, CaioToOn!
精彩评论