<?xml version="1.0" encoding="iso-8859-1"?><rss version="2.0">
<channel><title><![CDATA[ActionScript.org Flash, Flex and ActionScript Resources - Comments for article: Building A Better Array -- The Dictionary Class]]></title><link>http://www.actionscript.org/resources</link><description /><language>en-us</language><copyright><![CDATA[http://www.actionscript.org/resources]]></copyright><generator>N/A</generator><webMaster>general.redirect@gmail.com</webMaster><lastBuildDate>Mon, 23 Nov 2009 00:49:28 CST</lastBuildDate><ttl>20</ttl><item><title><![CDATA[Comment #1]]></title><link>http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment11876</link><description><![CDATA[You are actually wrong on a few points and a few of your examples are pretty misleading. You can get much the same functionality in AS 2.0 once you understand the nuances of the Object class and how to implement a proper hashing scheme.<br/><br/>
(Comment posted by Damion Murray at 11:17 pm, Thu 28th Aug 2008)]]></description><author>no@spam.com (Damion Murray)</author><pubDate><![CDATA[Thu, 28 Aug 2008 23:17:48 CDT]]></pubDate><guid isPermaLink="true">http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment11876</guid></item><item><title><![CDATA[Comment #2 (Reply to Comment #1)]]></title><link>http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment11903</link><description><![CDATA[As to being wrong, I can only spot one: it should have been apply not call in the final example or the "root" should have been left out and I will also admit to a certain level of ambiguity in a number of places.

As to the abilities of AS2, it is not a manner of understanding.  There is no way of having the following simply work:
[as] 
var arr:Array = new Array(); 
arr[movieClip1] = 'foo';
arr[movieClip2] = 'bar';
[/as].

Yes, there are ways to construct hashes and custom classes.  That is more than possible.  One might even construct an array of objects as such:
[as]
var arr:Array = new Array();
arr.push({key:movieClip1, value:'foo'});
arr.push({key:movieClip2, value:'bar'});
[/as]
but that would be writing custom code to compensate for the fact that there is no native support for a true hash.  In fact, there is no support for object[someNonStringOrNumber] = someValue; in AS2 at all.  Yes, there are work-arounds, but those are hardly the same as actual support.

That said, whether one can get support for this in AS2 is not the topic of the article.  In fact, AS2 is mentioned only once, and that is far from a main point.  The topic of the article is that the Dictionary class in AS3 can easily manage what the Array classes (from BOTH AS2 AND AS3) cannot.

(To the moderator, I am not trying to boost my own article, nor alter the rating.  If possible, please do not count the able).<br/><br/>
(Comment posted by C.W. Allen-Poole at 3:09 pm, Tue 2nd Sep 2008)]]></description><author>no@spam.com (C.W. Allen-Poole)</author><pubDate><![CDATA[Tue, 02 Sep 2008 15:09:50 CDT]]></pubDate><guid isPermaLink="true">http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment11903</guid></item><item><title><![CDATA[Comment #2 (Reply to Comment #1)]]></title><link>http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12161</link><description><![CDATA[Actually Damion Murray is right. You're mistaken on various points. 

1. A multi-dimensional Array (MDA) and a hash aren't synonyms. A MDA is exactly what it says: multi-dimensional, meaning that you have an Array of Arrays, whose elements you'll access with myArray[ i ][ j ] for instance.
A synonym for hash is generally speaking "Associative Array", but in AS we have another way to create associative arrays, which is by populating an array with objects, so it's best not to use that term for dictionaries.

2. Your first example is not an example of how to create a hash in AS (2 or 3) but is actually an example of how to manipulate an instance of a dynamic class. The Array class is dynamic which means that you can create properties on the fly, w/o CTE's or RTE's. And that's exactly what you're doing. You're using the array as an Object, not an array.

3. You're confusing keys and values.
About these lines of code:
dict[movieClip1] = 'foo'; 
dict[movieClip2] = 'bar'; 
You write:
"This means that dict now has two values stored: one corresponding to movieClip1, and another corresponding to movieClip2. "
But that's not true. The dictionary instance now has stored two keys (movieClip1, movieClip2) and two values ('foo' and 'bar')

4. this doesn't remove a value:
delete dict[movieClip1];
It removes a key (and therefore ALSO a value, but that's not the same)
removing a value can be done using:
dict[movieClip1] = null<br/><br/>
(Comment posted by creynders at 8:23 am, Fri 24th Oct 2008)]]></description><author>no@spam.com (creynders)</author><pubDate><![CDATA[Fri, 24 Oct 2008 08:23:01 CDT]]></pubDate><guid isPermaLink="true">http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12161</guid></item><item><title><![CDATA[Comment #2 (Reply to Comment #1)]]></title><link>http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12521</link><description><![CDATA[1. To the first point, I concede.  That was incorrect.

2. Actually, there is notable ambiguity about how to appropriately create a hash in AS2.  Note the comments here:
http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001261.html which endorse the use of Arrays as Hash objects, and then here:
http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001901.html#wp121158 which recommends against it.  Things are further complicated by the arguments array.  It generally functions in a similar manner to a normal array, but it also has additional properties -- making it more like an associative array.  

Depending on the circumstances, one may wish to use an Array or an Object.  Or, since we are talking about Actionscript, one may even use a MovieClip for this process.  There have been a number of times when it has proven more useful to have an array function as a hash, but admittedly, I will normally use Objects.  In this case, however, use of Array should be preferred since we are discussing Arrays and not dynamic classes.

3. I take issue with your complaint.  The statement was correct.  The dictionary object has two new values.  It may have two new keys as well, but that does not fundamentally change the nature of the statement's correctness, merely its completeness. 

4.  This is incorrect.  Assigning a value of null, zero, empty string, undefined, etc. is not removing but changing a value.   dict[movieClip1] = null means that dict[movieClip1] has a very real value, even though that value is worth nothing (and technically, if you wanted to have the key return no value, the correct way to approach this is to have the key assigned to undefined).<br/><br/>
(Comment posted by CW.Allen-Poole at 12:01 am, Mon 19th Jan 2009)]]></description><author>no@spam.com (CW.Allen-Poole)</author><pubDate><![CDATA[Mon, 19 Jan 2009 00:01:26 CST]]></pubDate><guid isPermaLink="true">http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12521</guid></item><item><title><![CDATA[Comment #5]]></title><link>http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12101</link><description><![CDATA[It Would be better and too good if u have shown a file which you have created with this script. Since i wasn't able to find it working in my file....<br/><br/>
(Comment posted by shyju at 1:31 am, Sat 11th Oct 2008)]]></description><author>no@spam.com (shyju)</author><pubDate><![CDATA[Sat, 11 Oct 2008 01:31:12 CDT]]></pubDate><guid isPermaLink="true">http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12101</guid></item><item><title><![CDATA[Comment #6]]></title><link>http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12465</link><description><![CDATA[@shyju: I agree.
So I made it for you:
import flash.utils.Dictionary;//...
var dict:Dictionary = new Dictionary();
function setAlpha(mc:MovieClip):void {
	mc.alpha /= 2;
}
function setWidth(mc:MovieClip) :void{
	mc.width /= 2;
}
dict[mc1] = setAlpha(mc1);
dict[mc2] = setWidth(mc2);

for (var i:Object in dict) {
	i.addEventListener(MouseEvent.CLICK, runFun);
}

function runFun(evt:MouseEvent) :void{
	dict[evt.target].call(root, evt.target);
	// Any time you are referencing a “Function object” --
	// i.e. a function passed as a parameter, or stored
	// somewhere other than the original spot it was written,
	// myFunc.call() will allow you to call the function
	// without a reference to its original name.
}<br/><br/>
(Comment posted by Cor at 7:40 am, Fri 2nd Jan 2009)]]></description><author>no@spam.com (Cor)</author><pubDate><![CDATA[Fri, 02 Jan 2009 07:40:43 CST]]></pubDate><guid isPermaLink="true">http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12465</guid></item><item><title><![CDATA[Comment #7 (Reply to Comment #6)]]></title><link>http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12522</link><description><![CDATA[I thought you might like to know, this portion of your code is incorrect:
dict[mc1] = setAlpha(mc1);
dict[mc2] = setWidth(mc2);

as well as

dict[evt.target].call(root, evt.target);

It should be:
dict[mc1] = setAlpha
dict[mc2] = setWidth
...
dict[evt.target].call(evt.target);

The first two because any time a function has parentheses after it, the function is called.  The third change is because Function.call takes only the parameters that the function normally receives.  Thus, dict[evt.target].call(root, evt.target); will cause an error.<br/><br/>
(Comment posted by CW.Allen-Poole at 12:05 am, Mon 19th Jan 2009)]]></description><author>no@spam.com (CW.Allen-Poole)</author><pubDate><![CDATA[Mon, 19 Jan 2009 00:05:57 CST]]></pubDate><guid isPermaLink="true">http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment12522</guid></item><item><title><![CDATA[Comment #7 (Reply to Comment #6)]]></title><link>http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment13202</link><description><![CDATA[Shouldn't this 
dict[evt.target].call(evt.target);

be this

dict[evt.target](evt.target);<br/><br/>
(Comment posted by Carl at 6:37 pm, Mon 6th Jul 2009)]]></description><author>no@spam.com (Carl)</author><pubDate><![CDATA[Mon, 06 Jul 2009 18:37:46 CDT]]></pubDate><guid isPermaLink="true">http://www.actionscript.org/resources/articles/804/1/Building-A-Better-Array----The-Dictionary-Class/Page1.html#Comment13202</guid></item></channel></rss>