Embedding assets in FlashDevelop


Embedding asstes into your FD project is pretty simple. In fact it is as easy as 1, 2, 3. One: Copy, two: embed, three: use. Let’s go!

1. Copy

Alright, with your assets ready you should create a folder in your project folder or even in src. For the following example I created the folder sounds for (obviuosly) sounds and copied the font directly into src.

The FD project folder

The FD project folder

2. Embed

Embedding a font efficiently means knowing which glyphs you need. The following is a great source for finding Unicode ranges.

	public dynamic class Main extends MovieClip
			source = 'BERLIN.TTF',
			fontName = "berlinSans",
			fontWeight = "bold",
			advancedAntiAliasing = "true",
			mimeType = "application/x-font",
			fontStyle = "normal",
			embedAsCFF = 'false',
			unicodeRange = 'U+0020,
					U+002E, U+002F,
					U+0027, U+00A9,
					U+00E4, U+00FC'
		private var berlinSans:Class;
		[Embed( source = 'sounds/SoundPop.mp3')]
		private var SoundPop:Class;
		public var soundPop:Sound;
		[Embed(source = 'sounds/sound12.mp3')]
		private var SoundSwap:Class;
		public var soundSwap:Sound;
		[Embed(source = 'sounds/WintersDream.mp3')]
		private var Music:Class;
		public var music:Sound;

All embeds are followed directly by private vars, defining the embedded assets as classes. To use them public vars are created. Caveat: If you create folders anywhere, remember the path ( for source)!

3. Use

		public function Main():void 
			music = new Music();
			soundPop = new SoundPop();
			soundSwap = new SoundSwap();

The fonts are used simply by referring to the fontName you set in the embed section. By setting yourTextField.embedFonts you can use your font.

			iFormat = new TextFormat();
			iFormat.font = "berlinSans";
			iFormat.color = 0xaaaaaa;
			iFormat.size = 24;
			gameName = new TextField();
			gameName.embedFonts = true;
			gameName.defaultTextFormat = iFormat;
			gameName.text = "yourText here";
			gameName.selectable = false;
			gameName.autoSize = TextFieldAutoSize.LEFT;

Pretty much always you should set yourTextField.selectable to false. As a player I am always a bit picky when it comes to buttons where the text selection tool shows up.

The same thing goes with graphics I think though I didn’t try that.


This entry was posted in as3, flash, mochiads, Tutorial and tagged , , , , . Bookmark the permalink.
Be Sociable, Share!

3 Responses to Embedding assets in FlashDevelop

  1. nikhil says:

    hello there!! can you tell me how to make a menu screen containing button play which on click should run my new file(like game will start )

    • kegogrog says:

      Now that is a pretty difficult question regarding the number of correct answers. It totally depends on how you use classes and your overall coding style.

      Now if you want to make a class for your screen (ScreenMenu.as) as a sprite, it could include another sprite acting as the button, which on click unloads the ScreenMenu instance and loads the ScreenGame class.

      If you’d like to privide me some more information on how it should look like, you can just write me a mail with some details and I may be able to help you (files must be compatible with either Flash CS3 or FlashDevelop).