2

I've got this weird problem and i just cant figure it out. I'm using the localToGlobal to get the coordinates for my character and do a hittestpoint on a level clip. Everything works fine in flash player 10.1. r52

But then i open the exact same .swf on a other machine running flash player 10.0 r22, and the hittesting doesnt work. I tried everything, tracing the parents etc.

The setup:

Main Class, in Main Class i add a Game class(Sprite). In the Game Class i add a Level Class(Sprite) and a Character Class(Sprite)

the 'camera' follows the character, and the Game class is moved arround.

So

Main (static x & y)> Game (dynamic x & y)> Level(static x & y) & Character (dynamic x & y) this is my code:

    private function checkLanded():Boolean
    {//this code runs on the character class, so 'this' = character
        var localPoint:Point = new Point(this.x, this.y + this.myHeight / 2 + 1);
        var globalPoint:Point = parent.localToGlobal(localPoint)

        if (Settings.levelGround.hitTestPoint(globalPoint.x,globalPoint.y,true) || Settings.levelPlatforms.hitTestPoint(globalPoint.x,globalPoint.y,true))
        {
            return true;
        }
        return false;
    }

So this code runs perfectly in flash player 10.1 but not in 10.0 Now for 10.0, instead of using parent.globalToLocal, i tried parent.parent.globalToLocal which does work in 10.0 and not in 10.1.

How can i make sure that this code will run in all flash players.

**edit- I fixed it, i moved the main class arround which somehow disturbed the flash coordinate system. I then tryed moving the game class arround and that seem to work. Still wondering why moving the main class arround doesnt work..


Please help me,

Thanks in advance,

Erik Sombroek

Erik
  • 21
  • 3
  • why are you using parent at all? If Character is an descendant of Sprite then it has `localToGlobal` itself. – shanethehat Jul 21 '11 at 14:26
  • @shanethehat Yes i know, but even using var globalPoint:Point = this.localToGlobal(new Point(0,0)) i have the same result – Erik Jul 21 '11 at 17:14
  • you can use backticks to highlight code in comments :) – shanethehat Jul 21 '11 at 17:46
  • @shanethehat, even when im using var `localPoint:Point = new Point(this.x+parent.parent.x,this.y+parent.parent.y + this.myHeight / 2); var globalPoint:Point = localPoint; –` (lol i figured it out haha) – Erik Jul 21 '11 at 17:50
  • What is `Settings.levelGround`, and where does it fit in the display tree as you list it in the question? – shanethehat Jul 21 '11 at 18:01
  • Settings is a class where i store the globals. Settings.levelGround references to a Sprite which is also added in the Game object – Erik Jul 21 '11 at 18:03

1 Answers1

0

this is a way to know the coordinates of a display object in reference to the stage

public function getDisplayObjectsRootCoord(target:DisplayObject):Point{
    var coords:Point = target.localToGlobal(new Point());
    return coords;
}

or to see if the mouse is over an item...

var target:MovieClip;
var stage:Stage;// make sure you have a reference to this
var mouseOverPanel:Boolean = target.hitTestPoint(stage.mouseX,stage.mouseY,true);
mihai
  • 4,184
  • 3
  • 26
  • 27