apache-flex 如何访问导入的FXG图形的viewWidth和viewHeight?

nkoocmlb  于 2022-11-01  发布在  Apache
关注(0)|答案(1)|浏览(126)

在我的ActionScript 3项目中,FXG图形会汇入为SpriteVisualElement的实体,如下所示:

// with the FXG file myPackage/myFXGFile.fxg
import myPackage.myFXGFile;
var myFXG:SpriteVisualElement = new myPackage.myFXGFile();
addChild( myFXG );

FXG文件中的“帧”是使用<Graphic>viewWidthviewHeight属性定义的。下面是一个简单图像的示例。它由一个矩形和一个更大的矩形组成,只有前者是视图“帧”的一部分。

<?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>

在代码中,我需要知道这个框架的尺寸,即viewWidthviewHeight的值,有没有办法从导入的文件中获取它们?有没有办法不需要手动解析FXG文件?

更新:我刚刚查看了SpriteVisualElement可用的所有方法和属性,getPreferredBoundsWidth()和-Height()似乎能完成我所寻找的内容。不过,我对Flex源代码没有足够的信心来找到这些值的来源,而且有几个条件让我不确定。这是正确的和推荐的方法吗?

bmp9r5qi

bmp9r5qi1#

SpriteVisualElement是继承自FlexSpriteflash.display.Sprite的类别。FXG是下列的执行严修:
如果使用ActionScript将FXG组件添加到应用程序中,则该组件得类型应为SpriteVisualElement .
除了上述getPreferredBoundsWidth()getPreferredBoundsHeight()之外,还有另外两种方法:

getLayoutBoundsHeight   ()  method   
public function getLayoutBoundsHeight(postLayoutTransform:Boolean = true):Number

Language Version :  ActionScript 3.0
Product Version :   Flex 4
Runtime Versions :  Flash Player 10, AIR 1.5

Returns the element's layout height. This is the size that the element uses to draw on screen.

Parameters
    postLayoutTransform:Boolean (default = true) — When postLayoutTransform is true, the method returns the element's bounding box width. The bounding box is in the element's parent coordinate space and is calculated from the element's layout size and layout transform matrix.

Returns
    Number — The element's layout height.

getLayoutBoundsWidth    ()  method   
public function getLayoutBoundsWidth(postLayoutTransform:Boolean = true):Number

Language Version :  ActionScript 3.0
Product Version :   Flex 4
Runtime Versions :  Flash Player 10, AIR 1.5

Returns the element's layout width. This is the size that the element uses to draw on screen.

Parameters
    postLayoutTransform:Boolean (default = true) — When postLayoutTransform is true, the method returns the element's bounding box width. The bounding box is in element's parent coordinate space and is calculated from the element's layout size and layout transform matrix.

Returns
    Number — The element's layout width.

有没有不需要手动解析FXG文件的解决方案?
使用FXG Editor作为替代。

参考资料

相关问题