<< Chapter < Page | Chapter >> Page > |
(Note that as of June 2010, the product named Flex Builder 3 has been replaced by a productnamed Flash Builder 4 to accommodate the release of version 4 of Flex. I will becovering both Flex 3 and Flex 4 in this series of lessons.)
Skeleton MXML code for a new Flex project
When you create a new Flex project in Flex Builder 3, a skeleton of the required MXML file is created for you. Listing 1 shows the contents of such askeleton MXML file.
<?xml version="1.0" encoding="utf-8"?><mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"></mx:Application>
(Listing 1 shows the skeleton code for a Flex 3 project. The skeleton code for a Flex 4 project is somewhat more complicated.)
The XML declaration
The line of code that begins with the left angle bracket followed by ?xml is called the XML declaration . It tells what version of XML is being used and also specifies the encoding scheme for the characters in thefile. An XML declaration should be included at the beginning of every XML document.
The root element
The line of text that begins with a left angle bracket and mx:Application is the start tag for the root element in the XML document. (The root element is always named Application in a Flex project.) At this point in the course, you should be able to identify the end tag for the Application element.
All XML documents have a root element. All other elements must be nested in the root element.
Attributes of the root element
The start tag for the root element in Listing 1 includes two attributes:
The layout attribute
The layout attribute specifies that components will be positioned on the computer screen using absolute coordinates. As you will see later, this is notwhat I want for my project so I will delete this attribute.
The namespace (xmlns) attribute
The more interesting attribute is the one named xmlns . The term xmlns is the required name for a namespace attribute. While it isn't necessary in general to include a namespace attribute in the rootelement, when a namespace attribute is included in the root element, it becomes the default namespace for the entire document.
Namespace is always required for a Flex project
It is always necessary to include the namespace attribute shown in Listing 1 in the main MXML document for a Flex 3 project. That is why Flex Builder 3includes it in the skeleton code for the project.
(Flash Builder 4 includes different namespace attributes in the skeleton code for a Flex 4 project.)
To make a long story short, the inclusion of the default namespace attribute shown in Listing 1 means that all elements with names that refer to componentsfrom the standard Flex 3 library of components must be prefixed with mx .
A viable Flex project
The code shown in Listing 1 is a viable Flex 3 project. You can compile it and run it. However, when you do, you won't see any output other than a blank areawith a default gray background in your browser window. So far, the project doesn't contain any Flex components such as labels and buttons.
Notification Switch
Would you like to follow the 'Introduction to xml' conversation and receive update notifications?