Undocumented functions in Flash. A huge annoyance: reset()

20 05 2010

Synopsis:

Today has been a really frustrating day. I am writing a new game, and I’ve been making great progress so far. It’s highly optimized for memory performance (so far) and probably as OOP as I’ve ever done. Needless to say I’m rather proud of it so far. It’s been pretty smooth sailing all along, until today. When I found that there is some undocumented behavior. I am using a methodology called Object Pooling. Which basically means I am re-using instances rather than re-creating them. However, as I was going along I hit a nasty little problem. As items came up for re-use all of the visuals were missing. Everything else was there in memory, but the screen was blank. You can imagine my frustration. An to prevent others from experiencing the same frustration, I’ve decided to write what I found here.

What I found:

The items in question eventually inherit from flash.display.Sprite. I was also implementing a custom interface which defined a single method.
function reset():void;

I had this so that when I put the object back into the pool I could call this method which would restore the instance back to it’s default state. However it seems that there is an undocumented “feature” that won’t let me name my function “reset”. Maybe I’m blind, but I couldn’t find it here:   http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Sprite.html#methodSummary When I would call that function all of the visual elements of that class would be erased when I tried to add it back to the display list. As soon as I renamed the function to “resetItem” everything worked perfectly again.

A Word of caution:

Unless you too want to experience countless hours of frustration, *DO NOT* name your functions “reset” when extending from Sprite**.

** I don’t know it it also occurs when extending other things. I didn’t want to take the time to check because I was pretty peeved.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s




%d bloggers like this: