Skip to content
July 23, 2008 / Shrikant Patil

Centralising Embedded Images of Application

Centralizing embedded image include creating a public class where all images required by the application are get embedded and declared as public static constants, which are get accessed any where within whole application, by importing the centralized embedded images class.

Say that we have three images which are going to be used in a application, classes and components, then create centralized embedded images class as follows;

package com
{
	public class AssetImages
	{
		[Embed(source="imgs/waiting.png")]
			public static const WAITING_ICON:Class;
		[Embed(source="imgs/busy.png")]
			public static const BUSY_ICON:Class;
		[Embed(source="imgs/idle.png")]
			public static const IDLE_ICON:Class;
	}
}

that’s pretty, Let you now access any of these embedded images by their constant reference in anywhere within your application, like as follows;

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="absolute">
	<mx:Script>
	<!&#91;CDATA&#91;
		import com.AssetImages;
			
		private function assignIcon():void{
			myButton.setStyle("icon",com.AssetImages.BUSY_ICON);			
		}
	&#93;&#93;>
	</mx:Script>
	
	<mx:Button id="myButton"
	 label="SampleButton"
	 click="assignIcon()"/>
</mx:Application>

This provides a centralized place for all embedded image of an application, so that any changes, updates are done in one place will get updated in overall application.

Advertisements

One Comment

Leave a Comment
  1. iaadamwilliamst4 / Sep 16 2011 2:05 am

    Hello guys & gals, I’m Ben jamin!

    I’m new to the forum and just saying hello.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: