0

我有一些代码,当我使用 Sprite 时,使用 addChild 时设置宽度和高度值,但使用 SpriteVisualElement 时,宽度和高度为 0。

        var sprite:Sprite = new Sprite();
        // ...
        sprite.cacheAsBitmap = true;
        sprite.transform.matrix = target.transform.matrix;
        sprite.addChild(bitmap); // width and height 250x65

        var spritevisualElement:SpriteVisualElement = new SpriteVisualElement();

        // ...
        spriteVisualElement.cacheAsBitmap = true;
        spriteVisualElement.transform.matrix = target.transform.matrix;
        spriteVisualElement.addChild(bitmap); // spriteVisualElement width and height 0x0

到底是怎么回事?我可以让 SpriteVisualElement 工作吗?

4

1 回答 1

2

您可以将边界用于实际大小(顺便说一句SpriteVisualElement,在方法中测量自身时也使用边界measure,但由于某些原因measure,flex 不会自动调用它,并且无法(我找不到)手动调用它):

var bounds:Rectangle = container.getBounds(container);
trace("size:", bounds.right, bounds.bottom); //<-- clip the container by the rectangle with origin at (0, 0)
trace("size:", bounds.width, bounds.height); //<-- full with/height

输出:

size: 100 100
size: 100 100
于 2013-01-29T20:00:57.180 回答