Friday, April 16, 2004

Wacky instance variable initialization

Came across something that is so wacky its hard to believe its true.

We had a component where we initalize an instance variable to an empty object in the class declaration as in:

var myVar = {};

Nothing too earth shattering here!

So its clear we should have an instance variable intialized to an empty object, so I could then do something like this;

myComp.myVar.empty=true;
or this
myComp.myVar.name=_name;

and then trace(myComp.myVar.name) will display the components instance name.

OK so whats the issue .. well it seems that the object that myVar points to is static (or global if you will) so now every instance will see myVar.name as the same name and NOT its own instance name.

We thought we must be missing something about using "{}" so we tried using new Object() instead but to no avail, the object created is always static and all instances will be pointing at the same object.

We resolved it in the end by leaving the var as undefined and then in the ancestor "init" method setting it to an empty object, then it all works correctly or I should say works as expected.

Ok there maybe be some obscure explanation for why this behavior is correct but at least its not obvious nor is it in line with what you would expect in other languages and could catch you out in building you own components so beware...

unless of course its a neat trick you would like to exploit...

Thursday, April 1, 2004

HTML and the standalone player

Ran into a quirky thing today, is it me or are the standalone player and the web player handling HTML slightly differently?

Trying making a movie that loads HTML using the XML object from an external file and insert it into a TextField(there is a sample app that does this in MX2004).

Running this in the web player and it works as you might expect but in the standalone player it seems that it recognises CRLF's in the text as well as BR tags. Thinking about it the problem could be in the XML object... is the XML object stripping CRLF's from the HTML that is being loaded in one version but not the other.

Ok so I guess the two players are different versions, I think from memory the standalone is 7014 and the web is 7019... have things changed?

Anyway if I am right, you need to be carefull about your HTML content if you think someone might be viewing using the standalone player as otherwise your pretty formatting will get screwed up.

Whilst we are talking about HTML and TextFields.. Since we can now load jpg's into the TexField and since these are usually being pulled over the web it can take some time to load. Wouldnt it be nice if there was some event to tell us the TextField had finished loading/rendering. As far as I know there isn't and the result is you must let the user watch your TextField rendering itself as the images are loaded one by one and so alter the layout.