开发者

How to get dimensions of only DisplayObjectContainer's *visible* contents?

A DisplayObjectContainer's dimensions change based on its contents.

That can be a LOT of contents, many of them with visible = false or masked, t开发者_如何学Pythonhus making them hidden. Is there a way to get only the visible contents of a DisplayObjectContainer similar to a TextField has the textHeight property, which gives you the exact dimension of what you see on-screen.


In this article, Colin Moock states that there is no such property for getting the "visible width" of a DisplayObjectContainer. That article does go into detail on the other ways of hiding an object, though, and it's well worth reading.

However, Moock later came up with a workaround: some code to check the actual visible pixels of an object and return the width & height based on that. This deals with masked objects, as well as objects with .visible set to false. His code is available here.


If it's a loaded object you can get the metadata width/height via loader.contentLoaderInfo.width etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜