ActionScript 3.0 :: Dictionary - How To Enumerate
Dec 19, 2010The great thing about dictionary: one can use objects as keys. The bad thing: compiler still believes that the keys are strings.
[code]...
The great thing about dictionary: one can use objects as keys. The bad thing: compiler still believes that the keys are strings.
[code]...
I can't use a "for in " loop to enumerate public properties of a custom class. So I have a class "ClassA" , which has some public properties. if I try :
PHP Code:
trace(classInstace.hasOwnProperty('property1'));// true
trace(classInstace.property1) // traces the property correctly
trace(classInstance.propertyIsEnumerable('property1')); // traces false ????
When I load an swf dynamically using the Loader, is there any way that I can retrieve the symbols that are exported as as3 classes? I know I can instantiate the symbols when I know the classname using loaderInfo.applicationDomain.getDefinition(fullyQualifiedName) as Class But I can't find something like applicationDomain.getDefinitions() which would result an array of fully qualified classnames, like
[Code]....
In order to send a POST request I need to enumerate all properties of a given object. This object may or may not be dynamic. I'm looking for the most elegant solution. This is what I've got so far:
[Code]...
The dictionary use strict equals(===) for key comparison, how to change the comparison, so I can use my standard for comparison, for example, I have a class named Student:
class Student{
var id:int;
var name:String;[code]....
I want Dictionary use id to compare if the two keys are equal, not use strict equal(===) to compare if the key is the same.
Is there any way to enumerate the shared objects created by an application? I'd like to create a number of individual shared objects and then enumerate them when the application starts again so it knows what's been stored. I want to store them individually because there could be a large number of them and I only need to use a few in any one application session and I don't want to read them all as one big shared object
I know I could put their names in a "master" shared object, enumerate that list of names, and manage it that way, but being able to enumerate the shared objects directly seems much cleaner.
I have to use many custom classes for a project, each class includes lots of elements(methods,properties) and I generally forget their names when coding. Is there any editor which I can enumarate the elements of my classes after pressing "." like Flash's built in classes?
View 8 RepliesNormally in Flex you use a collection like ArrayCollection as the dataprovider for components. I often have data stored as a dictionary whose values I would like to use as a dataprovider.
View 2 RepliesI'm working with a large set of hierarchical taxonomic terms, where each term ("203") has a matching "term203" movie clip on the stage, and am having trouble getting a recursive function to return all of a given term's descendants.There is a main Dictionary() object with the following nested organization for each term:
{ [object Movie Clip] : { "tid":203, "parent":99, "name":"Culture", selected:false, "otherData":"etc" } }
...where the [object Movie Clip]'s instance name would be "term203". All of these object:subObjectArray items ("terms") are stored in a master taxonomy:Dictionary() object.I've been trying to make a recursive function (which is in itself already a little above my head) that takes the click.target of a movie clip and returns a new Dictionary() object with all of the children and grandchildren and great grandchildren (etc) of that term, in the same, nested organization described above.
The code below traces the right number of recursive loops, but the returned Dictionary() object only contains the first run's terms (only the immediate children of the requested term).
var taxonomy:Dictionary = new Dictionary();
// ...Term info is loaded into taxonomy from a JSON-style text file)
// ...MOUSE_OVER event listeners are added to each
[code]....
I certainly do not claim to be the most efficient AS3 programmer, so I am open to alternative configurations. However, after trying static and nested Arrays, I would prefer to continue using the Dictionary() object as my main pool.As noted, only the immediate children end up animating in the revealChildren() function. It's mystifying to me then, that in the getAllChildren() function, all of the descendants trace sequentially (well in no particular order) in the output window.Also I can't get any sort of name or property out of the subSet Object. That could be the problem.I've only tested it as far as 'two generations,' but it seems that only the first round of calling the function successfully adds those terms to the new Dictionary() object and returns it intact to the animating function.
I'm often seeing others using a Dictionary object in their AS3 code that simply maps objects by String keys and wondering if there is any advantage at all of using a Dictionary over a simple Object if String keys are used. Anyone know any details on this? I would suppose that since an Object is more lightweight it should be faster and preferable over a Dictionary if used with String keys.
View 1 Replieswhy the Dictionary class ignores setPropertyIsEnumerable? I found this bug at bugs.adobe, seems the prototype might be involved in some devious way.Here is some test code:
var obj:Object = {
'a': 0,
'b': 1,[code]......
Notice that the Dictionary is still enumerating the property "a" even though it was told not to.
What is the correct way to determine if a Dictionary contains a particular key or not?
In Java I can do:
HashMap x= new HashMap();
x.containsKey("test"); // returns true/false
Is this the correct way in AS3?
var xictionary = new Dictionary();
x["test"] == null
[Code]...
in Java this: dict.keySet()
View 6 Repliessomehow plug a dictionary into flash which can be used to verify words in a word creation game I'd like to create..
Sounds perfectly feasible but I just wouldn't know where to start in finding it... are there ones which are readily available ?? (preferably free)
for (var k in dictionary)
{
var key:KeyType = KeyType(k);
var value:ValType = ValType(dictionary[k]); // <-- lookup
// do stuff
}
This is what I use to loop through the entries in a dictionary. As you can see in every iteration I perform a lookup in the dictionary. Is there a more efficient way of iterating the dictionary (while keeping access to the key)?
As the title suggests, is it possible to use AMF to encode/decode Dictionaries (without subclassing, that is)? For example, here's a test case:
[Code]...
What exactly is the difference between an object and a dictionary in Actionscript?
var obj:Object = new Object();
obj.something = "something";
var dict:Dictionary = new Dictionary();
dict.something = "something";
trace(obj.something, dict.something);
The trace statement seems identical...
Right now I am using ArrayCollection. But I want to change that to Set as I want make sure do duplicate values come.
var addressList:ArrayCollection = new ArrayCollection();
One way is I can use Dictionary and store addresses as a key. And I can just use keys to iterate. But I am looking for Java HashSet like implementation.
I am writing my destructor but I am not sure how to make sure that my Dictionary object is completely dismantled.
Do I just walk the keys and 'delete' the objects? If so do I need to destroy the keys? or are they already removed when the object is removed from the Dictionary?[code]...
I have an ARRAY which contains single symbols and DICTIONARY in where every symbol in array is attached to unique string, what I want to do - is to merge ARRAY and DICTIONARY together, and as a result receive RESULT_ARRAY where order of elements is equal to ARRAY but elements are replaced according to a DICTIONARY.
Code:
//for example
//this is what we have -
var originalA:Array = new Array ();
originalA[0]="y";
[code]...
I'm trying to do something along the following:
Code:
//Loop through all items in the dictionary to update each and every one
for (var key:DisplayObjectContainer in containerDict)
[code].....
Has anyone tried sending a Dictionary through the arguments of ExternalInterface.call()?What happens to it when it reaches the Javascript side, because from what I understand JavaScript does not have a Dictionary implementation.
View 4 RepliesIs there a way for flash to get the nature of a word (noun, verb, adverb, etc.) from a dictionary somewhere?
View 1 RepliesDoes Flex Dictionary maintain the order of its elements?
View 2 RepliesDoes Flash Actionscript have List and Dictionary equivalents? I've only found the documentation for the Array.
View 2 RepliesI am using Flex dictionary to store ValueObjects with Timestamp as the 'key' for each object.
Given a timestamp, I want to iterate over the dictionary starting from the given timestamp key value.
The Docs discuss the following for dictionary iteration, but this iterates from the first key-value pair.
for (var key:Object in myDictionary)
{
trace(key, myDictionary[key]);
}
In my parsley container, I'm instantiating an object 'A' that contains a Dictionary (flash.utils.Dictionary).
I would like to create this Dictionary using parsley and inject it to 'A'.
This dictionary pairs structure is: key=id of object 'B', value='B'
where object 'B' is also an object which is defined and created using parsley(so basically the pairs structure is and object id as a key and the object itself as the value).
Now, I have no problem creating 'A' and 'B', but can't seem to find the right way to create this dictionary using parsley, nor injecting it to 'A'.
So I am writing a program which uses Dictionary to store objects. For example
var dictionary:Dictionary=new Dictionary();
var myObject = new myObject(var1, var2, var3);
dicionary["key"]=myObject;
where var1, var2, and var3 are simply means of assigning values to variables in myObject.can I access values or functions that are found in myObject? In myObject class I have some getters and setters. Can I use a getter to get the value of var1 for example.
dictionary["keys"].getVar1()?
This is kinda related to my other question: flex dictionary bug? The HashMap has a method getValues() which returns an array of values:
[cODE]....
the loop for (var key:* in map) iterates the keys of the dictionary map, but it seems its implementation does it in some random way. What is the best way to write a test since I don't know what the array returned by getValues method will contain? I thought I could do it by calling the sort method, and compare the values, is there a better way to do it?assertEquals(map.getValues().sort(), "value A,value B,value C,value X,value Y,value Z");
its for managing several buttons that load different swf'sI do not know what to do with the last else bit.I understand all of it except "places it in cache with e.currentTarget as the key"cache is meant to be a dictionary which I do not really understand.
Code:
function menuClick(e:Event):void{
if (currentlyShowing != null){
[code].....