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:
Results:
PatheticBadOKGoodOutstanding!
5 rates

MXML

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.

MXML

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.

    Source: http://livedocs.adobe.com/flex/3/langref/statements.html#this

  3. Dec 13, 2011

    使用ActionScript添加组件可以更灵活的控制组件的现实方式及显示时间.


 

----------------------------------------

Resources