Tuesday, June 12, 2007

Array instantiation for actionscript classes

If you want to avoid some nightmares, don't instantiate the arrays in the variable definition inside a class.
i.e. DON'T do the following

class myClass {

var my_array:Array = new Array()

function myClass()
{
}

....
}


Coz this would end up with a behaviour similar to having the my_array defined as static. What I think that it is happening, is that it won't re-initialise the variables when you instantiate a class but will just give you a reference to the array. Thus each instance you create will have a reference to the same array. How dumb!

So the solution is ofcourse to move the array instantiation in the constructor, like so:

class myClass {

var my_array:Array;

function myClass()
{
my_array = new Array();
}

....
}

Monday, June 11, 2007

Dictionary service and getTextExtent

I'm still working on the word puzzle game so far.
I got this idea this morning, that when you manage to connect a word it would access an online dictionary service and give you a definition. Basically I was testing the game and I was forming words that I didn't ever hear before. So you can actually learn something by playing this game :)

I found this free dictionary service
http://services.aonaware.com/DictService/
I'm currently using it to request word definitions and then place them in a speech bubble.

I also worked on scrolling the speech bubble text if the definition didn't fit. I used the TextFormat.getTextExtent() method, even though it is errouneously marked as deprecated for Flash8.

Friday, June 8, 2007

Word list in Flash word game

I'm working on a word puzzle game for a client and I had the challenge to find if a word was created on a game board and had to access 28,000 words (taken from a word list found at http://wordlist.sourceforge.net/ which are used for spell checking, word games, etc)
Originally there were over 80,000 words but I trimmed off the long words which cannot be created on the board.

To overcome the slow speed of flash accessing a huge array, I split up the word list in 26 arrays (one for each letter). This was not enough. You could tell that the CPU was doing something since the animation stop until he checks the board. So I re-split each array into another 26 arrays. Flash doesn't have red-black trees (or is there??) so I had to improvise ;) This was the simplest and now you won't notice it is checking the board for 28,000 words :D.

Wednesday, June 6, 2007

Not much progress this week

Not much progress on the prototype this week. I'm currently busy doing a flash puzzle game for a client and also getting updated on all the changes (and problems/bugs) with AS3.

Monday, June 4, 2007

Player disconnections

It was a busy day, but I found some time for the flash game prototype ;). Started coding some support for player disconnections. The idea is that when a player disconnects, the other players will know that the other player was disconnected (by showing an icon in the HUD near the avatar which got disconnected). And then the player with the same username only can reconnect to the game session. We will also notify the player that he has a game pending and he can reconnect (without going to the lobby).

For now anyone can reconnect ;)
But we will get to the above semantics.

Debugging Flash Player 9 with a logfile

There has been some changes in Flash Player 9...
mainly that you cannot change where the log file will be saved.
You will find the flashlog.txt in C:\Documents and Settings\user_name\Application Data\Macromedia\Flash Player\Logs

You need the debug player/activex/plugin from here.

For more details on setting the necessary mm.cfg check out the docs.

Saturday, June 2, 2007

Trolls and ActionScript3

I have started coding the trolls which currently are very simple objects that just move horizontally. Nothing really intelligent.

I have also started learning a bit about AS3 (about time huh?). There are some new concepts which I'm reading about. It seems like they have taken a good direction into scrapping a lot of stupid stuff that was in AS1/2 like movie depth assigning ... they have have gone for a display list approach. I will comment more once I will start using it. They have changed so much that you have to read a bit about migrating the code to AS3. So I think it will be time well spent ;). Especially because of the optimizations they have done. FINALLY we have int and uint! (instead of just Number class), i.e. optimizations can be done by the compiler. Also no more removeMovieClip... you just set the reference to null, and a movie will be garbage collected.