Wednesday, June 18, 2008

Flex Woes

I've been experiencing a lot of strange behavior with Flex recently. I would add a new variable definition or an empty method to a class and all of a sudden, my application does not display. I was baffled by this for days.
I finally got the Flex Builder debugger to work and it gave me Error #1065: Variable is not defined error.
So I made sure all of my variables were defined....no luck. I even commented out every other piece of code, sometimes it would work, sometimes not. I then found out that this error message could also mean that your class is not public, or that you did not use an object, therefore it will not be included in the SWF file. All of which made no sense because all I did was add a variable declaration.
To make a long story short, the problem turned out to be with an XML object definition. I moved it to the end of my variable definition list and things started to work again. But this was a temporary solution. I have a feeling that putting the XML definition at the end of the list just ensured that the other variables would be defined before Flex errored out.
Eventually I removed the XML and put it in an object. I also made sure that all my XML was valid and all error cases were handled. Things have been working fine since then. I have a feeling that since I was breaking off pieces of the XML to be used in Flex containers that somewhere along the line something got corrupted. I still use pieces of the main XML and allow the Flex components to modify the pieces to modify the main XML document, I'm just a bit more careful about it. Using XML as a data storage mechanism for Flex has turned out to be a good thing and I'll be using it from now on.

No comments: