Today, I had some spare time on the train to London and created a little Array "class" (well, movie clip). It implements the most popular methods as well as some properties/behaviors that have been added as "methods" (push, pop, lookUp, assign, length, etc.)
Here's an example of usage (think of the Array movie clip as a static class that contains all the arrays in your app):
tellTarget ( "Array" ) { // Add first item, the string "Hello" name = "myArray"; item = "Hello"; call ("push"); }
It even comes with a suite of unit tests... yes, you read it here first -- unit tests for FlashLite
Wanna see an example of a unit test in Flash 4/FlashLite? Here goes:
tellTarget ( "Array" ) { index = 1; call ( "lookUp" ); } // Assert that the value at index 1 is "There" if ( eval ( "/Array:value" ) ne "There" ) { trace ( "Assert failed on testLookUp: Value should be \"There\"" ); failed++; } else passed++;
(OOPsters may keep their chuckles to themselves, thank-you-very-much!)
Download the FLA and take a look (flashlite_array.zip; 8kb). [MIT license, go crazy with it if you like!]
One caveat: It's considerably slower than rolling your own using eval on the same timeline/object. I'm actually not sure whether I'll end up using it on the little game I'm making and I'd appreciate your comments/thoughts.
The Array “class” for FlashLite article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.
Hey Aral, what are you doing playing with Flash Lite, didn’t think you were too fond of the idea! :p
Actually, it’s really funny going back to Flash 4 style code with hindsight and having been engrossed with AS2 for the last year and whatnot (Unit testing!!). Here’s a kind of string “utils class” that you might find useful:
http://richardleggett.co.uk/downloads/flashlite/string/StringFunctions.zip
Have a nice little virtual pet project coming along, will post it Fri night if interested.
Oh man, I didn’t know you could do StringFunctions:input_str … well that’s going to save me a few tellTargets and evals
It’s really kinda cool learning and re-learning this stuff (it probably would help if I just RTFM (well, the articles, at least that are out there!)
Isn’t it eerie how close the Flash 4/Lite way of working is to Assembly language… set some registers than do something
Very true, I dipped into ASM a few years ago but nothing major. Actually I was considering changing my StringFuncs:varname to the tellTarget code you are using, I can’t decide which method I prefer now.
Wouldn’t let anyone hear Flash Lite and Assembly in the same sentence though, might scare a few off :p, it’s not that bad people! The compiler is pretty intelligent in converting your dot syntax etc. Hope to see some more FL related posts in the future if you get time of course.
MOV AX, BX
NOOP
That’s all I remember from my assembly days.
Aral, justin everett posted some interesting “event” code for fl if you are looking for that to put in your game … I haven’t used it yet, but it looked like a good idea.
Happy flash-lite’ing.
Hopefully we’ll see AS2 syntax sometime in the future …
well guess what Richard i have checked your stringfunctions fla before reading this but i was so stuck up with the word array so couldnt get anything. So Aral saved my day.
By the way Aral i am Mehmet from Turkey nice to meet a fellow around owing to my curiosity i’ve made a lil research on you and found out that you did some awesome work, im proud