Array "class" for FlashLite
I've been playing with FlashLite as of late and it's actually not as difficult as I first thought (I first gave it a look and then gave up a few month's ago.) It feels naughty to be placing my code on the timeline, in movie clips, etc. again but there are many things you can do to make FlashLite apps and games easier to maintain.
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.
Comments
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.
by richardleggett on 2005-05-04 22:44:57
Isn't it eerie how close the Flash 4/Lite way of working is to Assembly language... set some registers than do something :)
by Aral Balkan on 2005-05-05 00:37:45
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.
by Richard Leggett on 2005-05-05 01:24:51
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 ... :)
by scottjanousek on 2005-05-05 02:04:34
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 :)
by mehmet on 2005-07-13 08:38:06