Setting width or height makes Sprite invisible

Hi there!
I’ve simple sprite added to the root. Everything’s fine untill I’m adding two lines: width=10 and height=10
After that, the sprite becomming invisible. What’s happening and what I’m doing wrong?

var s:Sprite = new Sprite();
s.width = 10;
s.height = 10;;, 10, 10);;


Setting width and height on DisplayObject’s (with the exception of TextField's) causes rendering issues. Refer to scaleX and scaleY for proper sprite scaling.

Apart from that, width and height variables are handled internally based on the maximum width and height of a Sprite’s collection of children. For example, two children side by side causes the maximum width of the parent sprite to match that of the right-most child. Same goes for height.

In the case of BitmapData, you can however set width and height at construction, and alter and manipulate pixels before then attaching the instance to a Bitmap instance.

1 Like

Not true. The problem here is setting the dimensions of an empty Sprite.

nochnoy: try drawing the circle first, before messing with width and height.

Perhaps I was thinking of the behaviour of the Flash target. Because if you do it in Flash, it causes everything to go blank.

1 Like

Evidence of inconsistent behaviour, but okay. Good to know.

It’s evidence of what I said above.

If you set width or height on a sprite that has nothing in it, that one sprite will break, but nothing else will.

If you put something in the sprite first, you can set width and height with no problems.