I learned how to utilize the Collection and Iterator patterns yesterday, thanks to Dan, the Java head (head of Java) at my job. I had previously asked Kenny B awhile ago, and he had explained it just as thoroughly, but typecasting to interfaces was a fuzzy subject, as was why one would do such a thing.
Additionally, so satisfy Google keyword searchs for said topic since the ones I found were pathetic, I hope to create a new tutorial this weekend on AMFPHP and utilizing the mx.utils.Collection, mx.utils.CollectionImpl, mx.utils.Iterator, and mx.utils.IteratorImpl. Contrary to the docs, the whole dragging of an SWC file to get the classes file to work doesn’t work; I tried. You have to get the files from the AS2 Remoting Source files download, as mentioned at Rich-Internet.
The only roadblock I’m having with them is I can’t get my authoring component to work. The code itself works beautifully, and I’m overjoyed at how neat Collections and Iterators are; you can do a crapload more than one could do using arrays and looping through them with far less code. However, following the docs to the T, I still couldn’t get my component properties inspector to show anything. If you know, let me know.
Secondly, something I saw in Moock’s book and in the docs which baffles me is the whole:
var value:Class = Class(something);
Now, I know do this to avoid a type-mismatch error:
var i:Number = 1;
var o = String(i);
var str:String = new String(o);
trace(str); // 1
trace(typeof(str)); // object
trace(str instanceof String); // true
The conversion of i to a string via using the String class constructor makes sense, as does Number (although, I recommend parseInt). But when the docs do like:
var button:ButtonC = ButtonC(someObj);
That's weird... it doesn't work. In the example they give for CompactDisk, the constructor does not do any initialization at all. Maybe it works in other languages but you cannot assume that doing the above will work like an attachMovie initialization object, and simply set the class's member variables to the value passed in; it only works for Intrinsic classes OR ones you've specifically wrote yourself. By Intrinsic, I mean:
s = String(num);
num = Number(s);
d = new Date(2004);
a = new Array("mic", "check");
But if you make a class CompactDisc, and don't do squat with your constructor, passing in an object into CompactDisc will NOT return a valid object. My example didnt' work till I did this myself:
if(arguments != null)
for(var p in arguments)
this[p] = arguments[p];
When I did that, she worked like a charm. My guess is, in Java or some other language, this just works:
var val:NewClass = NewClass(o);
Where o is some object with data, not of class NewClass, and by doing the above it returns a converted instance or something... whatever man, not in Flash. Do the above, and you get the same effect, though.