2

EDIT2: It seems that the big numbers are created because the movieclip doesnt hold any bipmapdata, but Im yet not sure about it, but my real mistake was that I just forgot "this" infront of one "getBounds" ... project size was to big and I couldnt find the bug =)

EDIT: tried to use seperate containers, for the movieclips, and did all this in the root class ... everything worked fine, when I used seperate containers and attached everything to the charakter class it got screwd up again

OLD: Hey I am making a game right now and I want to get the bounds of the charakter body. To understand how I did set the whole thing up I explain the hirarchy.

The class of my flash document is "game.as". "game.as" adds a Child of the class Charakter my Charakterclass has a Movieclip for every body part, for example the "head" every bodypart has a movieclip which contains the picture of the bodypart, in this case "head".

When I now try to use the getBounds(head.mc) inside the "head" class I get really weird results. ussualy something around x=64001, y=64001, width = 0, height = 0;

I found a way how to solve this problem by simply using the getBounds(head.mc) function not inside the head, but inside the Charakter class .... but this is not what I actually want to do, I would like to use the getBounds(head.mc) function inside the head class.

Any ideas why the results are so weird or what I have to do? Im very thankfull for every opinion, because this doesnt seem logical to me xD

tschery
  • 153
  • 2
  • 15

2 Answers2

3

getBounds() is inaccurate. Please read the following posts to understand the issue.

getBounds "wrong" results (Source)

When getting bounds of an object relative to it's OWN coordinate system, those values will NOT be scaled.

getBounds() returning incorrect height (Source)

Florent
  • 12,310
  • 10
  • 49
  • 58
bitmapdata.com
  • 9,572
  • 5
  • 35
  • 43
  • 2
    It is better to include the essential parts of the answer here and provide the link for reference. – Florent Aug 23 '12 at 14:24
  • oh thanks this is not what I was looking for but very helpfull anyways and Im sure this will solve a problem which Im going to encounter soon =D – tschery Aug 23 '12 at 14:56
2

From inside head_mc, try getBounds(this.parent); (you may want to test to see if the parent exists first) - this should give you the bounds of your head_mc as its container sees it, which I think is what you want, but called from inside head_mc, as you request.

bitmapdata is right, though - getBounds() can sometimes give some odd results. It looks to me like you might be asking the question before you add head_mc to the stage, and are therefore getting the undefined values for width/height/x/y.

Jude Fisher
  • 11,138
  • 7
  • 48
  • 91
  • thats what I thought too, that I asked to early and I was dealing with this problem for the last for hours ... probably I should just take a break and try it a few hours later because I am quite sure that I fully understood how getBounds() works .... thanks anyway man =) – tschery Aug 23 '12 at 14:34