Solved

creating flex dictionary , urgent

Posted on 2011-03-01
7
590 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
  • 4
  • 3
7 Comments
 
LVL 17

Accepted Solution

by:
deepanjandas earned 500 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
Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Flex organization chart 5 604
flex - list item renderer 7 675
Crossdomain Policy 3 689
Play RTMP without Flash 3 404
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…
With more and more people tethered to the internet, advertisers can reach you in new and creative ways. Push notifications on your smartphone, customized advertisements based on your previous searches, and email inboxes filled with promotional pitch…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now