MXML vs ActionScript 3.0

Flex components can be added to an application using MXML or ActionScript 3.0. Both code examples below display the same results.

previous page next page
Your Rating:
6 rates


Components are implicitly initialized when the user runs the application.

  • The Application class is a container
  • Components are added to an application as children objects.
  • MXML is compiled to ActionScript 3.0

ActionScript 3.0

Components are created and added to the display though an explicit call to the addControls() function when the user runs the application.

You need to add an initialize listener to the application object to call the function that adds the components (initialize="addControls()").
You need to explicitly attach the components to application object (this.addChild(photo))

Rendered Samples

Both applications render the same even though one adds components using MXML and the other using ActionScript 3.0 code.


ActionScript 3.0

previous page next page

  1. Jun 27, 2008

    In the functions createImage() and createPhotographer()
    what does the term "this" refer to?
    Is it the application instance, or <mx:Script> create an instance of some class that "this" refers to?

  2. Jul 18, 2008

    The 'this' keyword is a reference to a method's containing object. When a script executes, the 'this' keyword references the object that contains the script. Inside a method body, the 'this' keyword references the class instance that contains the called method.


  3. Dec 13, 2011