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

发布于 2024-11-28 22:12:18 字数 1374 浏览 0 评论 0原文

在我的 ActionScript 3 项目中,FXG 图形作为 SpriteVisualElement 如下:

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

FXG 文件具有使用 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文件的解决方案?

更新:我刚刚查看了 SpriteVisualElementgetPreferredBoundsWidth() 和 -Height() 可用的所有方法和属性> 似乎正在做我正在寻找的事情。不过,我对 Flex 源没有足够的信心来找到这些值的来源,并且有几个条件让我不确定。这是正确且推荐的方式吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2024-12-05 22:12:18

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 编辑器 作为替代方案。

参考

SpriteVisualElement is a class that inherits from FlexSprite and flash.display.Sprite. FXG is an instance of this:

If you use ActionScript to add an FXG component to an application, it should be of type SpriteVisualElement.

There are two other methods outside of the aforementioned getPreferredBoundsWidth() and 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. 

Is there a solution without parsing the FXG file manually?

Use an FXG Editor as an alternative.

References

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文