Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

creating flex dictionary , urgent

Posted on 2011-03-01
7
Medium Priority
?
607 Views
Last Modified: 2012-05-11
here it goes, I am getting the result object from backend through blazeds . form this result object i was able to populate the data into advanced datagrid . there will be a  id for each message. The same message will have 2 states i.e.initialize and complete. when we get the same message with complete status , we have to update the initialize to complete, so we do not populate the same message with two states. for this purpose I want to create a dictionary which will hold the key  of the conversation ids adn values of the message.

pls suggest me how to implement this?
0
Comment
Question by:arigs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 17

Accepted Solution

by:
deepanjandas earned 2000 total points
ID: 35013901
The best is to create a Dictionary Object in Flex like this having the keys and values in an xml:
The Dictionary class:
package
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.Font;
	import flash.utils.Dictionary;

	public class DictionaryManager extends EventDispatcher
	{
                private static var instance : DictionaryManager;
                public static const STATIC_DICTIONARY_PATH:String = "configs/dict_static.xml";
		public static const LOADED:String = "dictionaryLoaded";

		private var dictionary:Dictionary;
		
		public function DictionaryManager( enf:SingletonEnforcer )
		{
			dictionary = new Dictionary();
		}
		
		public static function getInstance() : DictionaryManager 
		{
			if( instance == null ) instance = new DictionaryManager( new SingletonEnforcer() );
			return instance;			
		}
		
		public function set xml( path:String ):void 
		{
			var urlLoader:URLLoader = new URLLoader();
			urlLoader.addEventListener( Event.COMPLETE, onXMLLoadCompleteHandler );
			urlLoader.addEventListener( IOErrorEvent.IO_ERROR, onXMLLoadErrorHandler );
			urlLoader.load( new URLRequest( path ) );
		}
		
		private function onXMLLoadCompleteHandler( event:Event ) : void
		{
			EventDispatcher( event.currentTarget ).removeEventListener( event.type, arguments.callee );
			
			var urlLoader:URLLoader = URLLoader( event.target );
			var xml:XML = new XML( urlLoader.data );
			urlLoader.close();
			urlLoader = null;
			
			parse( xml );
		}
		
		private function onXMLLoadErrorHandler( event:IOErrorEvent ) : void
		{
			//
		}
		
		public function parse( config:XML ) : void
		{
			var itemList:XMLList = config.item;
			for each ( var prop:XML in itemList ){
				dictionary[String( prop.@id )] = String( prop.translate );
			}

                        var loadedEvent:Event = new Event( DictionaryManager.LOADED );
			dispatchEvent( loadedEvent );
		}
		
		public function get( value:String ) : String
		{
			return ( dictionary[value] == null ) ? value : dictionary[value];
		}
	}
}
internal class SingletonEnforcer{}

Open in new window

//use this in your code
var dictionaryManager = DictionaryManager.getInstance();
dictionaryManager.addEventListener( ResourceManager.LOADED, onDictionaryLoaded, false, 0, true );
dictionaryManager.xml = DictionaryManager.STATIC_DICTIONARY_PATH;

private function onDictionaryLoaded( event:Event ):void
{
	dictionaryManager.removeEventListener( DictionaryManager.LOADED, onDictionaryLoaded );
			
}

Open in new window

The xml:
//sample xml
<?xml version="1.0" encoding="UTF-8"?>
<dict lang="en">
	<item id="key1"><translate><![CDATA[Value1]]></translate></item>
	<item id="key2"><translate><![CDATA[Value2]]></translate></item>
	<item id="key3"><translate><![CDATA[Value3]]></translate></item>
  	<item id="key4"><translate><![CDATA[Value4]]></translate></item>
  	<item id="key5"><translate><![CDATA[Value5]></translate></item>
</dict>

Open in new window


Warm Regards
Deepanjan Das  
0
 

Author Comment

by:arigs
ID: 35013952
Hi Deepan,

          Thank you for ur reply and valuable time. I am using the cairngorm , so can i declare a variable of dictionary in modellocator? in that case, is what you have written  applicable, still ?
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35013990
Yes, it is applicable for any actionscript 3.0 project.

In your model locator declare the DictionaryManager in the constructor as :
_dictionaryManager = DictionaryManager.getInstance();

Open in new window


Then create a getter to be accessible in all places in your application like this:
public function get dictionaryManager() : DictionaryManager
{
	return _dictionaryManager;
}

Open in new window



In your main mxml where you initialized your ModelLocator, write the following code before initializing your application:
//use this in your code
var model:ModelLocator = ModelLocator.getInstance();
model.dictionaryManager.addEventListener( ResourceManager.LOADED, onDictionaryLoaded, false, 0, true );
model.dictionaryManager.xml = DictionaryManager.STATIC_DICTIONARY_PATH;

private function onDictionaryLoaded( event:Event ):void
{
        model.dictionaryManager.removeEventListener( DictionaryManager.LOADED, onDictionaryLoaded );
                        
}

Open in new window


Now you can access your dictionary from anywhere like this:
model.dictionaryManager.get("key1");

Open in new window


Warm Regards
Deepanjan Das  
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 

Author Comment

by:arigs
ID: 35018174
Hi Deepanjan,

                         If You don't mind can you pls give your email id, so i can send screenshots of my project which will give clear picture of my problem.

Thanks
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35018720
I am not sure if its right to provide emails here, Kindly access my email through my blog in the link http://www.experts-exchange.com/M_6015623.html from my personal blog.

Warm Regards
Deepanjan Das
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 35018722
Also you may send the screenshots here as file attachments.

Warm Regards
Deepanjan Das
0
 

Author Closing Comment

by:arigs
ID: 35070044
gr8 approach
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question