Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何访问导入的FXG图形的viewWidth和viewHeight?_Actionscript 3_Apache Flex_Viewport_Dimension_Fxg - Fatal编程技术网

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

Actionscript 3 如何访问导入的FXG图形的viewWidth和viewHeight?,actionscript-3,apache-flex,viewport,dimension,fxg,Actionscript 3,Apache Flex,Viewport,Dimension,Fxg,在我的ActionScript 3项目中,FXG图形作为以下实例导入: // with the FXG file myPackage/myFXGFile.fxg import myPackage.myFXGFile; var myFXG:SpriteVisualElement = new myPackage.myFXGFile(); addChild( myFXG ); FXG文件具有使用的viewWidth和viewHeight属性定义的“帧”。下面是一个简单图像的示例。它由一个以较大矩形为

在我的ActionScript 3项目中,FXG图形作为以下实例导入:

// with the FXG file myPackage/myFXGFile.fxg
import myPackage.myFXGFile;
var myFXG:SpriteVisualElement = new myPackage.myFXGFile();
addChild( myFXG );
FXG文件具有使用
viewWidth
viewHeight
属性定义的“帧”。下面是一个简单图像的示例。它由一个以较大矩形为中心的矩形组成,只有前者是视图“框架”的一部分


在代码中,我需要知道此帧的尺寸,即
viewWidth
viewHeight
的值。有没有办法从导入的文件中获取它们?有没有不手动解析FXG文件的解决方案


更新:我刚刚浏览了
SpriteVisualElement
可用的所有方法和属性,
getPreferredBoundsWidth()
和-
Height()
似乎符合我的要求。不过,我对Flex源代码没有足够的信心来找到这些值的来源,有几个条件让我不确定。这是正确且推荐的方法吗?

SpriteVisualElement
是继承自
FlexSprite
flash.display.Sprite
的类。FXG就是这样一个例子:

如果使用ActionScript将FXG组件添加到应用程序中,则其类型应为
SpriteVisualElement

除了上述
getPreferredBoundsWidth()
getPreferredBoundsHight()
之外,还有两种其他方法:

getLayoutBoundsHeight()方法 公共函数getLayoutBoundsHeight(postLayoutTransform:Boolean=true):数字 语言版本:ActionScript 3.0 产品版本:Flex4 运行时版本:Flash Player 10,AIR 1.5 返回元素的布局高度。这是元素用于在屏幕上绘制的大小。 参数 postLayoutTransform:Boolean(默认值=true)-当postLayoutTransform为true时,该方法返回元素的边界框宽度。边界框位于图元的父坐标空间中,并根据图元的布局大小和布局变换矩阵进行计算。 退换商品 编号-元素的布局高度。 getLayoutBoundsWidth()方法 公共函数getLayoutBoundsWidth(postLayoutTransform:Boolean=true):数字 语言版本:ActionScript 3.0 产品版本:Flex4 运行时版本:Flash Player 10,AIR 1.5 返回元素的布局宽度。这是元素用于在屏幕上绘制的大小。 参数 postLayoutTransform:Boolean(默认值=true)-当postLayoutTransform为true时,该方法返回元素的边界框宽度。边界框位于图元的父坐标空间中,并根据图元的布局大小和布局变换矩阵计算。 退换商品 编号-元素的布局宽度。 有没有不手动解析FXG文件的解决方案

使用另一种方法

参考资料


据我所知,FXG文件不是Sprite的子类;它们存在于Flash对象层次结构之外。我有点困惑,你到底在进口什么;但是如果它是一个实际的FXG元素,您应该能够执行mySprite.viewWidth和mySprite.viewHeight。当然,命名约定很混乱,因为有一个Sprite实例!=FXG.它们似乎被很好地浇铸到了
Sprite
,至少,因为上面的
mySprite:Sprite
工作正常。将实例用作
spark.core::SpriteVisualElement
(如
getQualifiedSuperclassName()
所建议)或
myPackage.myFXGFile
不会为其提供任何
viewWidth
属性;很难进一步评论。精灵没有viewWidth属性。您确定使用的是FXG图形而不是精灵吗?你能给我们看看你的myFXGFile代码吗?我在Flex应用程序中使用FXG元素的方法是创建一个指向FXG文件的类变量;然后我使用该类的实例来创建FXG资产的实例。这与Flex框架的工作方式是一致的。谢谢您的评论。我已经用更多信息编辑了这篇文章,并删除了有关将角色转换为
Sprite
的部分。张贴的代码是否足够?对于“指向FXG文件的类变量”,您的意思是使用[Embed]?否;没有嵌入。类似这样的内容:var myFXGInstanceClass:Class=com.myFXGFile;myfXGInstance:DisplayObject=新的myFXGInstanceClass();
<?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>
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.