<?xml version="1.0" encoding="utf-8"?>
<!--
This is a sample that demonstrate the usage of [Bindable] tag in Flex
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import BindableModel;
[Bindable]
public var model:BindableModel = new BindableModel();
]]>
</mx:Script>
<mx:TextArea x="23" y="181" width="446" height="240" text="{model.msg}"/>
<mx:Button x="123" y="86" label="Test Private Property by Setter and Getter" click="model.changeMsg()"/>
<mx:Button x="675" y="86" label="Test Public Property" click="model.changeFlag()"/>
<mx:TextArea x="529" y="181" width="460" height="240" text="{model.flag}"/>
</mx:Application>
<!--
This is a sample that demonstrate the usage of [Bindable] tag in Flex
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import BindableModel;
[Bindable]
public var model:BindableModel = new BindableModel();
]]>
</mx:Script>
<mx:TextArea x="23" y="181" width="446" height="240" text="{model.msg}"/>
<mx:Button x="123" y="86" label="Test Private Property by Setter and Getter" click="model.changeMsg()"/>
<mx:Button x="675" y="86" label="Test Public Property" click="model.changeFlag()"/>
<mx:TextArea x="529" y="181" width="460" height="240" text="{model.flag}"/>
</mx:Application>
BindableModle.as
package
{
import
flash.events.Event;
import
flash.events.EventDispatcher;
public
class
BindableModel
extends
EventDispatcher
{
/*
* Constructor
*/
public
function
BindableModel()
{
}
[
Bindable
]
public
var
flag:String =
"Hope is a good thing!"
;
/*
* private Members
*/
private
var
_msg:String=
"This is a just a message!\n"
/*
* Setter and Getter
*/
public
function
get
msg():String
{
return
this
._msg;
}
[
Bindable
(name=
"msgChanged"
)]
public
function
set
msg(message:String):
void
{
this
._msg = message;
}
public
function
changeMsg():
void
{
this
._msg +=
"\n"
+
"If you have a dream ,you gotta protect it!"
;
this
.dispatchEvent(
new
Event(
"msgChanged"
));
}
public
function
changeFlag():
void
{
this
.flag +=
"\n["
+
new
Date().toTimeString()+
"]AHa,Look at me.I have changed the flag again!"
;
}
}
}
转载于:https://blog.51cto.com/liumm/328446