0
votes

I have some code that when I use a Sprite the width and height values ares set when using addChild but when using a SpriteVisualElement the width and height are 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

What is going on? Can I make SpriteVisualElement work?

1

1 Answers

2
votes

You can use bounds for the actual size (btw SpriteVisualElement uses bounds as well when measures itself in the measure method, but by some reasons measure isn't called by flex automatically and there isn't way (I can't find it) to call it manually):

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

output:

size: 100 100
size: 100 100