4
USING FLEX 4.5
Getting started
Dernière mise à jour le 19/6/2011
The following example shows a simple “Hello World” application that contains just an <s:Application> tag and
three child tags, the
<s:Panel> tag and the <s:Label> tags, plus a <s:layout> tag. The <s:Application> tag
defines the Application container that is always the root tag of an application. The
<s:Panel> tag defines a Panel
container that includes a title bar, a title, a status message, a border, and a content area for its children. The
<s:Label>
tag represents a Label control, a very simple user interface component that displays text.
<?xml version="1.0"?>
<!-- mxml\HellowWorld.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Panel title="My Application">
<s:Label text="Hello World" fontWeight="bold" fontSize="24"/>
</s:Panel>
</s:Application>
Save this code to a file named hello.mxml. MXML filenames must end in a lowercase .mxml file extension.
About XML encoding
The first line of the document specifies an optional declaration of the XML version. It is good practice to include
encoding information that specifies how the MXML file is encoded. Many editors let you select from a range of file
encoding options. On North American operating systems, ISO-8859-1 is the dominant encoding format, and most
programs use that format by default. You can use the UTF-8 encoding format to ensure maximum platform
compatibility. UTF-8 provides a unique number for every character in a file, and it is platform-, program-, and
language-independent.
If you specify an encoding format, it must match the file encoding you use. The following example shows an XML
declaration tag that specifies the UTF-8 encoding format:
<?xml version="1.0" encoding="utf-8"?>
About the <s:Application> tag
In addition to being the root tag of an application, the
<s:Application> tag represents a Spark Application container.
A container is a user-interface component that contains other component sets, and uses layout rules for positioning its
child components. By default, the Spark Application container lets that you set the position of its children. In the
previous example, you set the layout of the container to VerticalLayout so that the Application container automatically
lays out its children in a vertical column.
You can nest other types of containers inside an Application container, such as the Panel container shown above, to
position user interface components according to other rules. For more information, see « Visual components » à la
page 281.
About namespaces
In an XML document, tags are associated with a namespace. XML namespaces let you refer to more than one set of
XML tags in the same XML document. The
xmlns property in an MXML tag specifies an XML namespace.
In Flex, you typically define three namespaces:
• xmlns:fx="http://ns.adobe.com/mxml/2009" The namespace for top-level ActionScript elements, such as
Object and Array, and for tags built into the MXML compiler, such as
<fx:Script>.
• xmlns:mx="library://ns.adobe.com/flex/mx" The namespace for the MX component set.
Praat mee over dit product
Laat hier weten wat jij vindt van de Adobe Flex 4.5. Als je een vraag hebt, lees dan eerst zorgvuldig de handleiding door. Een handleiding aanvragen kan via ons contactformulier.