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 />
 </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>

相关文章:

  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2021-12-02
  • 2021-10-13
猜你喜欢
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2021-06-02
  • 2021-08-19
  • 2022-12-23
相关资源
相似解决方案