FXG in ActionScript 3

Mon Oct 12 12:58:53 2009

With the introduction of the Flex 4 SDK (Gumbo), it is now possible to import FXG files into your ActionScript and MXML projects. In this example, I will be using an illustration of a flower, aptly named Flower.fxg which was created in and exported from Illustrator CS4.

I would also like to add that what I'm about to do is also possible using SVG files, and for anyone using TextMate or FlashDevelop, this looks a very promising replacement to the Flash IDE and library.

First, you need to create a package and embed your vector graphic as a Class. Embedding required the Flex SDK, so for Flash users who wish to try this out, you will need to get the Flex SDK and point flash in the right direction.

The finished article looks something like this:
package  {
      import flash.display.Sprite;
      import flash.events.MouseEvent;

      [SWF(width='500', height='500', backgroundColor='#FFFFFF', frameRate='60')]
	
      public class Main extends Sprite {
 	
	    [Embed(source='Flower.fxg')]
	    private var Flower:Class;
	    private var flower:Sprite = new Flower();
 
	    public function Main() {
	       addChild(flower).addEventListener(MouseEvent.CLICK, clickHandler);
	       flower.buttonMode = true;
	    }
		
	    private function clickHandler(event:MouseEvent):void {
	       trace("Flower Clicked");
            }
      }
}

After this class has been created, simply compile it making sure that the FXG file is where it's supposed to be. In my case, I used TextMate and the FLEX 4 SDK to compile. The result is as follows.

Get Adobe Flash player

Pretty cool stuff if you ask me. Anyway, for anyone interested, you can find the files for this here


← back

Most recent posts

  1. Convert Font Suitcase to TTF in 3 Easy Steps
  2. Rain or Shine - Weather Forecast Available Now!
  3. Getting around Apple's silly rules for iOS 10
  4. Localising App Names for iOS and Android
  5. Today - Powerful To-Do App Now Available on iOS & Android

Search site:

Apps by Ubacoda.com

Click the app icons to see more info


Archives

Categories