
24
Chapter 2: Using MXML
You can write an MXML application in a single file or in multiple files. MXML supports custom
components written in MXML files, ActionScript files, and files created using the Flash MX 2004
authoring environment. Some MXML tags, such as the
<mx:Script>
tag, have a property that
takes a URL of an external file as a value. For example, you can use the
source
property in an
<mx:Script>
tag to reference an external ActionScript file instead of typing ActionScript directly
in the body of the
<mx:Script>
tag.
Note:
You specify a script in the
source
property of an
<mx:Script>
tag. You do not specify
ActionScript classes in the
source
property. For information on using ActionScript classes, see
Chapter 18, “Creating ActionScript Components,” in
Developing Flex Applications
.
MXML supports the following types of URLs:
•
Absolute; for example:
<mx:Style source="
http://www.somesite.com/mystyles.css
">
•
A path used at runtime that is relative to the context root of the Java web application in which
a Flex application is running; for example:
<mx:HTTPService url="
@ContextRoot()/directory/myfile.xml
"/>
•
A path used at compile-time that is relative to the context root of the Java web application in
which a Flex application is running; for example:
<mx:Script source="
/myscript.as
"/>
•
Relative to the current file location; for example:
<mx:Script source="
../myscript.as
"/>
Writing a simple application
Because MXML files are ordinary XML files, you have a wide choice of development
environments. You can write MXML code in a simple text editor, a dedicated XML editor, or an
integrated development environment (IDE) that supports text editing.
Note:
MXML filenames must end in a lowercase .mxml file extension.
The following example shows a simple “Hello World” application that contains just an
<mx:Application>
tag and one child tag, the
<mx:Label>
tag. The
<mx:Application>
tag is
always the root tag of a Flex application. The
<mx:Label>
tag represents a Label control, a very
simple user interface component that displays text.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >
<mx:Panel title="My Application" marginTop="10" marginBottom="10"
marginLeft="10" marginRight="10" >
<mx:Label text="Hello World!" color="#6601D7" fontSize="24" />
</mx:Panel>
</mx:Application>
Содержание FLEX-GETTING STARTED WITH FLEX
Страница 1: ...Getting Started with Flex...
Страница 4: ...4 Contents...
Страница 22: ...22 Chapter 1 Introducing Flex...