Variable assignment by value rather than by reference in ActionScript 3 for Arrays
Something that has bugged me a few times, but I needed to figure out this time, as a Flash beginner, is that because everything is an object (and thus an instance of a class, including primatives) you more often than not (unless using primitives/statics) bind everything because you’re always passing variables by reference.
Coming from a Basic/C/Perl/PHP background where you can pass things by either value or reference it took a while for me to figure out how to just copy an array! Since $array2 = $array1; in PHP for example would copy array 1 to array 2, in ActionScript it will bind array 2 to array 1, and weirdly there seems to way (I can find yet) to pass objects by value. But having found the concat function:
array2 = array1.concat();
http://www.kirupa.com/forum/showpost.php?p=2230759&postcount=4
… you can create a copy of array 1 by returning a new Array object with identical contents. Having seen some deep copy examples I’m assuming that most objects come supplied with copy methods so I don’t think it will be a problem in future, but something that newbies to the language may need to be aware of.
Leave a comment
Categories
- Been knackered for days on end, long day with relatives today then most of tomorrow in the office doing downtime maintenance. I should rest!
- Dinner with my mom, couz and uncle (@ Gold Mine) http://t.co/pj4iA2Ul
- Om nom nom http://t.co/Kd2CIzs9
- I'm at Westfield London Shopping Centre (Shepherd's Bush, Greater London) w/ 13 others http://t.co/b2kCzQOG
- Off to see relatives (@ Northampton Railway Station (NMP) w/ 2 others) http://t.co/3ekCATN8
Recent Posts
- Use Zend_Log_Writer_Firebug to debug AJAX requests using Firebug
- Using Zend_Db_Profiler_Firebug to show database queries per page
- Checking $mixed parameter type for PHP methods
- “concrete5 cannot parse the PATH_INFO or ORIG_PATH_INFO information provided by your server.”
- Enable hibernation on HP MicroServer for Windows Home Server v1




