【问题标题】:I get error when importing fxg into flex 4.6 project将 fxg 导入 flex 4.6 项目时出现错误
【发布时间】:2012-03-30 19:10:02
【问题描述】:

我使用 Inkscape 和 fxg 插件制作了一个 fxg 文件。它被称为 BugattiVeyron.fxg

我还使用 flex sdk 4.6 和 FlashDevelop 4 创建了 AS3 项目,并使用这样的导入语句导入此文件

import BugattiVeyron;

并像这样实例化它

private var bugatti:BugattiVeyron = new BugattiVeyron ();

使用 FD4 中的构建按钮不会出现任何错误,但是当我运行它时,我会收到此错误,尽管当我消除所有错误时,文件已很好地导入并且我可以向其中添加事件。

错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::updateCallbacks()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7345]
at mx.core::UIComponent/set nestLevel()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:4189]
at spark.core::SpriteVisualElement/http://www.adobe.com/2006/flex/mx/internal::addingChild()[E:\dev\4.y\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:2247]
at spark.core::SpriteVisualElement/addChild()[E:\dev\4.y\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:2211]
at resources::BugattiVeyron_Text_2126220941/createText()
at resources::BugattiVeyron_Text_2126220941()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at mx.core::FlexSprite()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\FlexSprite.as:61]
at spark.core::SpriteVisualElement()[E:\dev\4.y\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:88]
at resources::BugattiVeyron()[resources\BugattiVeyron-generated.as:10]

所以我收到此错误,但在我消除错误后导入了文件。

可能是什么问题,有什么想法吗?

【问题讨论】:

  • 1) 请贴出代码 2) 在调用 createText() 方法时检查 BugattiVeyron_Text 实例是否为空!
  • 我将 svg 中的所有文本都创建为矢量路径,为什么我仍然会收到有关文本的错误?
  • 可能是 fxg 本身已损坏?也许 Inkscape 插件不能很好地导出。你怎么看?
  • 也许您需要将您的 FXG 资产键入为 SpriteVisualElement。所以你可以这样声明:private var bugatti:SpriteVisualElement = new BugattiVeyron ();

标签: actionscript-3 apache-flex flex4.5 inkscape fxg


【解决方案1】:

我自己在这个问题上苦苦挣扎,终于想出了如何让它发挥作用。有两种方法。

您的 FXG 文件需要与 Main.as 位于同一目录中才能这样调用它:

import BugattiVeyron;

当然,如果您将图像资源放在另一个文件夹中,则必须在项目中设置类路径才能引用 FXG 文件。显然我们不能像这样访问另一个目录中的 FXG 文件:

import ../lib/BugattiVeyron

如果您在 FlashDevelop 中右键单击您的项目并从上下文菜单中单击“属性”,您将能够将您选择的目录添加为类路径,以便访问您的 FXG 文件。在我的例子中,我添加了 lib 作为项目的类路径。这使我能够像您之前尝试的那样导入我的资产。

import BugattiVeyron;
public class Main extends Sprite {
  var bugatti:BugattiVeyron = new BugattiVeyron();
..some code here...
}

希望这会有所帮助,我挣扎了一周试图弄清楚这一点。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,特别是在尝试从 FlashDevelop 中的纯 AS3 项目(无 MXML)中实例化包含文本(<RichText> 元素)的 FXG 时。我能够毫无问题地导入和使用其他不包含 RichText 的 FXG 文件。

    我对确切的细节有点模糊,但似乎错误是由于调用 createText()(在你的情况下为 resources::BugattiVeyron_Text_2126220941/createText())而发生的,因为 Flex 库没有为纯函数初始化AS3 应用程序。最简单的解决方案是在 MXML 而不是 AS3 中定义应用程序,即

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application 
      xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:bv="*"
    >
    <bv:BugattiVeyron/>
    </s:Application>
    

    而不是

    import BugattiVeyron;
    public class Main extends Sprite {
      var bugatti:BugattiVeyron = new BugattiVeyron();
    }
    

    (更多相关问题请参见:[Possible to use Flex Framework/Components without using MXML?。查找“Flex 4 的必要更新”部分。)

    或者,如果您不希望 Flex 库的运行时开销,您可以编辑 FXG 以将文本转换为路径。这应该适用于仅限 AS3 的项目,但如果有其他 FXG 功能遇到类似问题,我不会太惊讶。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      相关资源
      最近更新 更多