纯标记语言
Module
<mx:Model id="shippingModel" source="data/shipping.xml" />
自定义的Module
<mx:Model id="order">
<name>{name.text}</name>
<address>{address.text}</address>
<city>{city.text}</city>
<state>{state.selectedItem.data}</state>
<zip>{zip.text}</zip>
<email>{email.text}</email>
<creditCard>
<cardType>{cardType.selectedItem.data}</cardType>
<cardNumber>{cardNumber.text}</cardNumber>
<cardHolder>{cardHolder.text}</cardHolder>
<cardExpMonth>{cardExpMonth.text}</cardExpMonth>
<cardExpYear>{cardExpYear.text}</cardExpYear>
</creditCard>
</mx:Model>
界面上各个控件数据的一致性,控件数据和Model的一致性,无需用户写代码维护
内置的验证控件: <mx:EmailValidator field="order.email"/>
可对一个控件进行扩展:自定义的属性、方法、事件,非常强大
<mx:VBox xmlns:mx="http://www.macromedia.com/2003/mxml" verticalGap="0" width="100%" height="100%">
<mx:Metadata>
[Event("change")]
</mx:Metadata>
<mx:Script>
var dataObject;
var selectedItem;
function setValue(str: String, item: Object) {
if (dataObject == item) return;
if (item==undefined) {
visible = false;
return;
} else {
dataObject=item;
visible=true;
}
}
</mx:Script>
</mx:VBox>
引入CSS 和 Script
<!-- The ActionScript code for this class is externalized in a separate .as file for better readability -->
<mx:Script source="flexstore_script.as"/>
<!-- Style sheet used in this application -->
<mx:Style source="flexstore.css"/>
Script中定义的类,变量可以在mxml中直接引用
Dynamic Class:
In some cases, however, you might want to add and access properties or methods of a class at runtime that aren’t defined in the original class definition. The dynamic class modifier lets you do just that. For example, the following code adds the dynamic modifier to the Person class discussed previously:
dynamic class Person2 {
var name:String;
var age:Number;
}
Now, instances of the Person class can add and access properties and methods that aren’t defined in the original class, as shown in the following example:
var a_person:Person2 = new Person2();
a_person.hairColor = "blue"; //no compiler error because class is dynamic
trace(a_person.hairColor);
Subclasses of dynamic classes are also dynamic, with one exception. Subclasses of the built-in MovieClip class are not dynamic by default, even though the MovieClip class itself is dynamic. This implementation provides you with more control over subclasses of the MovieClip class, because you can choose to make your subclasses dynamic or not:
class A extends MovieClip {} // A is not dynamic
dynamic class B extends A {} // B is dynamic
class C extends B {} // C is dynamic
class D extends A {} // D is not dynamic
dynamic class E extends MovieClip{} // E is dynamic