Associative Arrays in ActionScript 3.0

Sometimes something very simple takes hours of your time just to figure out what’s going wrong.
I was doing a XML parsing and I was trying to save a part of information in a multi-dimensional Associative  Array.

And the problem was so easy that I would never ever guess something has been changed in AS 3.0 , till I stuck in the middle and spend hours to figure out what’s the problem.
A very simplified version of the issue is like this :


var my_arr:Array=new Array();
my_arr['test']    =    'xxx';
trace(my_arr.length); // returns 0

So as you can see, none of the properties and methods of Array won’t work for associative arrays. [refering to Adobe’s help].

Again referring to the same Help document you should use object Class whenever you need something like an Associative  Array.

Hope it will help someone out.

Advertisements

ActionSctip 3.0 Event Object

ActionScript 3.0 has perfect way of handling events.

It is different from the way it used to be in previous versions, but in this version it has become mature and powerful. I highly recommend you to read chapeter 12 of Essesntial ActionSctipt 3.0 by Collin Moock. You’ll definitely learn alot.

The new structure is great and as soon as you learn it, you’ll love it.

One of the tricky issues could be the differences between these two properties of MouseEvent Object : target vs currenttarget.
This is a quick and great article about it, I love the way he concluded the article :

– if we associate the event to an empty MovieClip, best to use the property target
– if we associate the event to a MovieClip containing different objects, best to use the property currentTarget

Unlearning is difficult

It has been a long time since I did my last projects in Flash / ActionScrip2.0 [cityofcaspian] & [Toboggan]. And since ActionScript 3.0 came out I hadn’t a chance to go and figure my own way out around it. You know most of the times a good chance would be a real project.

I have been busy mostly with PHP and CodeIgniter for the last 1 year and half. I’ll talk more about them later. But as I was taking the “Advanced Programming Practices” course at school, the professor told us that the project is a simulation of the RISK game and students are allowed to do it in whatever programming language they prefer, having in mind they need to provide certian artifacts to the professor and should improve their programming skills.

While he was telling us about the project requirements, I was totally sure that it could be done perfectly in Flash. But finding team mates with the same interests in a Masters program which  everybody is just blindly fascinated to Java, was so hard. But eventually it was such a great pleasure for me to find some other people who had experiences in Flash before and wanted to do it in Flash/ActionScript.

None of us had any experience in AS3.0, but I suggested as we are going to use ASdoc and ASunit, it’s better to do it in ActionScript3.0 and that would be a great chance for us to learn the new language.

Wow! It’s an amazing language, and it’s far from the old ActionScript2.0 which was simple but having lots of its own problems. Thinking in AS2.0 way but trying to implement it in AS3.0 application just not gonna work out… tons of “compiler errors”! I’m pretty sure if we didn’t know anything about AS2.0 we would have found our ways much faster.

We are finding our ways around after a while, but having the very strict time restriction has left us behind the schedule and what we expected from ourselves.

This ActionScript2.0 VS ActionScript3.0 document helped us alot.