03 - Introduction to MXML What is MXML? MXML one of the two languages \u200b\u200bused for creating Flex applications. It is a hierarchical programming language. This means that there is a node and this node will be hanging new nodes. In turn, each of the descendant nodes of the first node may have other descendants.
If the reader does not understand the concept of node, perhaps it is best to us to go more slowly.
What is a hierarchical structure and what is a node? A node is the unit used when working with hierarchies. It may be useful to see a small graphic. (See figure 01)
Image 01: Hierarchy of Nodes In image 01 you can see a tree or graph. As can be seen, the nodes (units within the tree) have a hierarchy. We shall see in the image 01 as follows:
- Node A has two children: Node B and Node C.
- Node A has no parent node.
- Node B has no children.
- Node B has as a parent to Node A.
- Node C has 2 children: Node Node D and E.
- Node C is father to Node A.
- Node D has no children.
- Node D is node C. father E
- Node has no children.
- Node E is node C. father
Perhaps there are more observations but with these reaches.
Definitions:
- Node A hanging all nodes. This means that Node A is the root the tree. A hierarchical tree can not have 2 roots.
- Nodes B, D and E do not have children, that is why they are called Sheets.
reread the definition of MXML to see if we have more clear now.
But then how do you create an application using MXML hierarchy? All MXML applications start with a node in the same way the trees start at its root. In this case, MXML root node determines that it will create an application called Application . Application node will drop all child nodes for the case will be the components (buttons, dropdown lists, text fields, etc.).
The portion of code that will then correspond to the application that was created in the post entitled "Understanding the work environment (IDE)." In this chapter we have created an application that contains a label entitled "First Tag". Just that.
Code 01: First Application
analyze the code created a bit below but first we must talk a little bit of syntax (just slightly).
nodes in MXML, syntactically, are called tags. A tag begins with the symbol
\u0026lt; and ends with the sign
> . Viewing the code tags will notice that there are 4 total:
- \u0026lt;? Xml version = "1.0" encoding = "utf-8"? >
- \u0026lt; mx: Application xmlns: mx = "http://www.adobe.com/2006/mxml" layout = "absolute" >
- \u0026lt; mx: Label text = "First Tag" / >
- \u0026lt; / mx: Application >
nodes with child nodes, as is Node Application , function with a pair of tags: an open and closed. At the root node of the application is Application, therefore, has a couple of tags to indicate you have kids.
The opening tag begins with the symbol \u0026lt; and ends with > but the end tag starts with the symbol \u0026lt;/ and ends with > .
All tags that are between the start tag and end tag of a specific tag will become children of this. That is why the tag is a child node Label Application. The Label tag is between the start tag and end tag Tag Application.
However, if a node is a leaf of the tree, this will be represented by a single tag that begins with the symbol \u0026lt; and end with the symbol /> . This is the case Tag Label. The tag in question is a piece of the application because it does not contain a pair of tags opening and closing.
Thus
be arming our application. They go to the root node nesting components.
know that many questions arise in this instance but we have to be patient to answer them all. While the obvious question would be (or at least to me) "If I have more than one component how is that sorted as I want? ", well, that will be answered shortly, you first have to learn more.
Attributes nodes nodes, besides having a name (Application, Label), have attributes. The attributes indicate properties of the components themselves. The clearest example in view is the Text attribute of the Label component. (See code 02)
Code 02: Component Label
The Label component's text property allows us to modify the text displayed by the Label component.
Similarly the Application component attributes. In 03 you can see that Application has a layout and a xmlns attribute.
Code 03: Application
The value of the attribute or property layout is "absolute" and the xmlns attribute is "http://www.adobe.com/2006/mxml ".
is possible that the xmlns attribute of the Application component is a little confusing. For now, ignore them. Most of the attributes that we see will be rather similar to the text of the Label attribute. Ie attribute = "value."
Attributes serve to modify any behavior, shape, size, position, etc. component.
Now if we are able to answer the following question:
If I have more than one component how is it sorted as I want? We will continue the previous example to show how to add more components and are located within the application.
- If we have not followed the various tutorials of progress until we can download the project by clicking here: Introduction to MXML
- To learn how to import the project, see the chapter: Import Projects
- After importing the project will open the application and enter the mode FlexAr.mxml "Source."
- Between Label and the closing tag of the application, add a TextInput tag that has the property "x" equal to 100 (see code 04). This will make the tag is equal to 100 pixels to the right of the upper right corner of the application. The position is relative to the position of the parent node. Under the TextInput
- add a Label tag with the attribute "text" as a "second label" and the attribute "and" equal to 25. (See code 05)
- Under the latter add a TextInput with the attribute "x" equal to "100" and the attribute "and" with a value of "25." (See code 05)
- Run the application. We'll see how they were placing the components.
Code
04
Code 05
And the word the left of the ":" for each MXML tag? We in each MXML tag, a syntax like this: "mx: TextInput. We know that refers to the TextInput component that is used for text input, but ... What is the word that is on the left? The answer is
Namespace or namespace. In Flex you can create your own components. This means that we can have a component called "MiTextInput." Assuming that our custom component does not want to call it "MiTextInput" but simply "TextInput". How would the application to know which component is being referenced?
The answer is the namespace. We have 2 components with the same name from the namespace. That is, in our project we have "mx: TextInput" and we can have "foo: TextInput.
In the second line of code that we see the following:
xmlns: mx = "http://www.adobe.com/2006/mxml" . Xmlns
is XML Name Space
mx is the name we put to
http://www.adobe.com/2006/mxml namespace is the location of the components with that namespace
Usually, when we create our own folder structure within the project will look like this:
xmlns: foo = "com.miproyecto.componentes .*" This define that when you type "foo: "The application looks for all components are in the structure created by us .*
com.miproyecto.componentes
One last question to address in this post ...
In what is the first line of the application? The first line of the application is:
This line indicates which version of XML that the browser has to interpret that character encoding is used.
are mandatory every time you create an application. There is not much to say about it, we call it bureaucracy. Yet we should not worry about it since the Flex Builder 3 is responsible for writing for us.
Finally! All these simple tasks we have given a small notion of what is MXML. I hope they have served and as I said before, if something is not clear, alert!