I was wondering what happens to the code contained in an <mx:Script> tag. If I define a function tehre, it just becomes a member function of the generated class. But I noticed that it seems OK for the compiler if I just write some (static) method calls there (specifically, I call Font.registerFont()). It works fine, but I feel kind of guilty for doing this, because I have no idea what’s really happening and when the code gets executed.
I was wondering what happens to the code contained in an <mx:Script> tag. If
Share
Following the advice of http://www.Flextras.com‘s answer, I kept the generated Actionscript classes and had a look. The code inside
<mx:Script>tags is simply put in the class body as-is. Knowing that, I could dig into the Flex livedocs and came across the following paragraph in the section about class definitions:So, putting statements inside a
<Script>tag in an MXML file is equivalent to putting code in astaticblock in a Java class definition.