2

I made an fxg file using Inkscape and the fxg plugin. It is called BugattiVeyron.fxg

I also created AS3 project using flex sdk 4.6 and FlashDevelop 4 and import this file using the import statement like this

import BugattiVeyron;

and instantiate it like this

private var bugatti:BugattiVeyron = new BugattiVeyron ();

Using the build button in FD4 does not give any errors, but when i run it I get this error although when I dismiss all the errors the file is beign imported well and I can add events to it.

the error:

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]

so i get this error but the file is imported after I dismiss the errors.

what could be the problem, any idea?

Vlad
  • 2,739
  • 7
  • 49
  • 100
  • 1) please post the code 2) check if BugattiVeyron_Text instance is not null when calling the createText() method ! – Adrian Pirvulescu Mar 14 '12 at 12:37
  • I created all text in the svg to be vector path, why do I still get errors about text? – Vlad Mar 14 '12 at 12:58
  • is maybe the fxg itself is corruppted? Maybe the Inkscape plugin doesnt export well. What do you think? – Vlad Mar 14 '12 at 13:16
  • 1
    Perhaps it is that you need to type your FXG asset as a SpriteVisualElement. So you would declare it like this: `private var bugatti:SpriteVisualElement = new BugattiVeyron ();` – Sunil D. Apr 03 '12 at 05:56

2 Answers2

3

I struggled with this issue myself and finally figured out how to get it working. There are two ways.

Your FXG file needs to be in the same directory as your Main.as in order to call it like this:

import BugattiVeyron;

But or course if you have your image assets in another folder you will have to set a class path in your project in order to reference the FXG file. Obviously we can't access the FXG file in another directory like this:

import ../lib/BugattiVeyron

If you right click on your project in FlashDevelop and click on Properties from the context menu you will be able to add your directory of choice as a classpath in order to access your FXG file. In my case I added lib as a classpath for the project. This enabled me to import my asset like you previously tried doing.

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

Hope this helps, I struggled for a week trying to figure this out.

CodeEngie
  • 417
  • 2
  • 5
  • 10
0

I ran into the same problem, specifically when trying to instantiate an FXG that contained text (a <RichText> element) from an AS3-only project (no MXML) in FlashDevelop. I was able to import and use other FXG files that didn't contain RichText without any trouble.

I'm a little hazy on the exact details, but it seems that the error occurs as a consequence of the call to createText() (resources::BugattiVeyron_Text_2126220941/createText() in your case) because the Flex library isn't initialized for a pure AS3 application. The simplest solution is to define the application in MXML rather than AS3, i.e.

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

instead of

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

(More on this in a related question: [Possible to use Flex Framework/Components without using MXML?. Look for the "necessary updates for Flex 4" section.)

Alternatively, if you don't want the runtime overhead of the Flex libraries, you can edit your FXG to convert the text to paths. This should work with AS3-only projects, but I wouldn't be too surprised if there were other FXG features that ran into similar problems.

Community
  • 1
  • 1
James
  • 1