flex入门小例子

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
	xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	width="500" height="300"
	creationComplete="init()">
	<mx:Script>
		<![CDATA[
			import mx.managers.PopUpManager;
			import mx.collections.ArrayCollection;
			
			[Bindable]
			private var notes:ArrayCollection = new ArrayCollection();
			
			private var addNoteScreen:AddNote;
			
			private function init():void
			{
				addNoteScreen = new AddNote();
				addNoteScreen.addEventListener("SaveNote", saveNote);
			}
			
			private function addNote():void
			{
				PopUpManager.addPopUp(addNoteScreen, this, true);
				PopUpManager.centerPopUp(addNoteScreen);
				addNoteScreen.author.text = "";
				addNoteScreen.topic.text = "";
				addNoteScreen.description.text = "";
			}
			
			private function saveNote(e:Event):void
			{
				var note:Note = new Note();
				note.author = addNoteScreen.author.text;
				note.topic = addNoteScreen.topic.text;
				note.description = addNoteScreen.description.text;
				notes.addItem(note);
				PopUpManager.removePopUp(addNoteScreen);
			}
		]]>
	</mx:Script>
	<mx:Panel title="Notes"
			  width="100%" height="100%"
			  layout="vertical" horizontalAlign="right"
			  paddingTop="3" paddingLeft="3" paddingRight="3" paddingBottom="3">
		<mx:DataGrid dataProvider="{notes}" width="100%" height="100%">
			<mx:columns>
				<mx:DataGridColumn headerText="Author" dataField="author" width="80"/>
				<mx:DataGridColumn headerText="Topic" dataField="topic" width="100"/>
				<mx:DataGridColumn headerText="Description" dataField="description"/>
			</mx:columns>
		</mx:DataGrid>
		<mx:Button label="Add Note" click="addNote()"/>
	</mx:Panel>
</mx:Application>


 
 
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
				layout="absolute" width="348" height="218"
				title="Add A Note">
	<mx:Metadata>
		[Event(name="SaveNote")]
	</mx:Metadata>
	<mx:Script>
		<![CDATA[
			import mx.managers.PopUpManager;
			
			private function close():void
			{
				PopUpManager.removePopUp(this);
			}
			
			private function save():void
			{
				this.dispatchEvent(new Event("SaveNote"));
			}
		]]>
	</mx:Script>
	<mx:Label text="Author" x="35" y="10"/>
	<mx:TextInput id="author" width="150" x="84" y="8"/>
	<mx:Label text="Topic"  y="36" x="42"/>
	<mx:TextInput id="topic" width="150" x="84" y="34"/>
	<mx:Label text="Description"  y="62" x="10"/>
	<mx:TextArea id="description" width="234" height="77" x="84" y="61"/>
	<mx:Button label="Cancel" click="close()" x="193" y="146"/>
	<mx:Button label="Save" click="save()" x="264" y="146"/>
</mx:TitleWindow>


 
 
 package
{
 public class Note
 {
  public var author:String;
  public var topic:String;
  public var description:String;
 }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值