0

I'm trying to send a sprite to function method.

However I could not get sprite width, height.. I don't know why this make a problem.

Could you give me an advice for this?

function mouseClick(evt:MouseEvent) { // click event
    var s:Sprite = new Sprite();
    s.width = 595;
    s.height = 842;
    s.x = s.y = 0;
    addChild(s);
    dothis(s);
}

function dothis(s:Sprite){
    trace("s.width : "+s.width + " / s.height : "+s.height);
    // s.width and s.height returns 0 value always..
}

As you see, I got results of sprite's width and height are 0 always.

Why this happen to me?

Richard
  • 351
  • 4
  • 17

1 Answers1

1

Since your Sprite does not contain anything (assuming it will later), the width/height will always be zero.

Sprite -> DisplayObjectContainer -> InteractiveObject -> DisplayObject-> EventDispatcher -> Object

If you follow the Sprite object inheritance, width/height are exposed in the DisplayObject class and per the notes in that class:

Except for TextField and Video objects, a display object with no content (such as an empty sprite) has a width of 0, even if you try to set width to a different value.

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Thank you very much. However I try to add a movieclip(not empty) using addChild into sprite. I check the width/height value of sprite, The result was same as well. :( – Richard Apr 07 '16 at 07:17