In my ActionScript 3 project, FXG graphics are imported as instances of SpriteVisualElement
as follows:
// with the FXG file myPackage/myFXGFile.fxg
import myPackage.myFXGFile;
var myFXG:SpriteVisualElement = new myPackage.myFXGFile();
addChild( myFXG );
The FXG files have "frames" defined using the viewWidth
and viewHeight
properties of <Graphic>
. An example of a simple image follows. It consists of a rectangle centered on a larger rectangle, with only the former being part of the view "frame".
<?xml version="1.0" encoding="utf-8"?>
<Graphic viewWidth="100" viewHeight="200" xmlns="http://ns.adobe.com/fxg/2008" version="2">
<Rect id="rect1" width="120" height="240" x="-10" y="-20">
<fill><SolidColor color="#FF0000"/></fill>
</Rect>
<Rect id="rect1" width="100" height="200" x="0" y="0">
<fill><SolidColor color="#0000FF"/></fill>
</Rect>
</Graphic>
In the code, I need to know the dimensions of this frame, i.e. the values of viewWidth
and viewHeight
. Is there any way to obtain them from the imported files? Is there a solution without parsing the FXG file manually?
Update: I just looked through all methods and properties available to SpriteVisualElement
, and getPreferredBoundsWidth()
and -Height()
seem to do what I'm looking for. I'm not confident enough with the Flex source to find the origin of those values, though, and a couple of conditions make me unsure. Is this the right and recommended way?