demo.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  creationComplete="init()"
 layout="absolute">
 <mx:Script>
  <![CDATA[
   import com.Person;
   [Bindable]
   internal var currentItem:Person;
   internal function init():void {
   var p1:Person=new Person();
   p1.name="张三";
   p1.age=40;
   p1.address="北京";
   p1.career="工程师";
   var item1:listItem=new listItem();
   item1.p=p1;
   item1.addEventListener("selectItem",selectHandler);
   p_name.addChild(item1);
   item1.y=0;
   var p2:Person=new Person();
   p2.name="李四";
   p2.age=20;
   p2.address="广州";
   p2.career="学生";
   var item2:listItem=new listItem();
   item2.p=p2;
   item2.addEventListener("selectItem",selectHandler);
   p_name.addChild(item2);
   item2.y=item2.height*2;
   }
   internal function selectHandler(evt:Event):void{
   if(evt.target==evt.currentTarget){
   currentItem=listItem(evt.target).p;
   }
   }
  ]]>
 </mx:Script>
 <mx:Model id="employees">
  <employees>
  <employ>
  <name>老张</name>
  <age>30</age>
  <address>一路</address>
  <career>工程师</career>
  </employ>
  <employ>
  <name>小李</name>
  <age>20</age>
  <address>二路</address>
  <career>学生</career>
  </employ>
  <employ>
  <name>大刘</name>
  <age>25</age>
  <address>三路</address>
  <career>老师</career>
  </employ>
  
  </employees>
 </mx:Model>
 <mx:Panel id="p_name" x="21" y="20" width="136" height="271" layout="absolute" title="员工列表">
 
 </mx:Panel>
 <mx:Panel x="206" y="20" width="273" height="271" layout="absolute">
  <mx:Label x="29" y="28" text="姓名"/>
  <mx:Label x="29" y="69" text="年龄"/>
  <mx:Label x="29" y="115" text="住址"/>
  <mx:Label x="29" y="162" text="职业"/>
  <mx:TextInput id="txtName" x="83" y="26" text="{currentItem.name}"/>
  <mx:TextInput id="txtAge" x="83" y="67" text="{currentItem.age}"/>
  <mx:TextInput id="txtAddress" x="83" y="113" text="{currentItem.address}"/>
  <mx:TextInput id="txtCareer" x="83" y="160" text="{currentItem.career}"/>
 </mx:Panel>
 
</mx:Application>

person.as:

 

package com
{
 import mx.charts.chartClasses.StackedSeries;
 
 public class Person
 {
  public var name:String;
  public var age:int;
  public var address:String;
  public var career:String;
  public function Person()
  {
  }

 }
}

listItem.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml" width="91" height="20"
 click="onClick(event)" text="{p.name}"
 >
 <mx:Script>
  <![CDATA[
   import com.Person;
   [Bindable]
   public var p:Person;
   internal function onClick(evt:MouseEvent):void{
   dispatchEvent(new Event("selectItem"));
   }
  ]]>
 </mx:Script>
 
</mx:Label>

posted on 2009-12-30 16:39  sweting  阅读(219)  评论(0编辑  收藏  举报