Embedding assets in FlashDevelop

FDthumb

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
	{
		[Embed(
			source = 'BERLIN.TTF',
			fontName = "berlinSans",
			fontWeight = "bold",
			advancedAntiAliasing = "true",
			mimeType = "application/x-font",
			fontStyle = "normal",
			embedAsCFF = 'false',
			unicodeRange = 'U+0020,
					U+0041-U+005A,
					U+0061-U+007A,
					U+0030-U+0039,
					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";
			addChild(gameName);
			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.

Yoho!

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

3 Responses to Embedding assets in FlashDevelop