Google analytics code

Monday, August 10, 2009

Flex: using mxml files as classes

Another thing I learned while working with Flex is that each MXML file can be treated like a class. You can import them and call the functions defined within like a method. This can be very useful when loading element into the stage.

It's also important to note that methods and properties are available once you've created the object. If you have defined something to run on creationComplete it won't run until the object is added to the stage with addChild.


import util.Example;
private function init() : void {
var example:Example = new Example;

//run function from external MXML file

//add the mxml file to the stage


public function example_function() : void {
trace('running function example');

private function init() : void {
trace('now all the elements inside are available');

No comments:

Post a Comment

If you found this page useful, or you have any feedback, please leave a comment.