我想获取标签元素在列表中的位置,
但我明白了8 0 8 0 (Global position)x:8,y:0
那是不对的,我该怎么办,谢谢
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://www.myflexhero.com/share/flex-hero-flex4/flex-hero-components/flex-hero-graphics/822 -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
>
<fx:Script>
<![CDATA[
import mx.core.UIComponent;
protected function getListChildAt(part:List,n:int):Label {
var child:UIComponent = part.dataGroup.getChildAt(n) as UIComponent;
var child_1:Label = child.getChildAt(0) as Label;
return child_1;
}
protected function show():void
{
var item:Label = getListChildAt(myList,0) as Label;
var item2:Label = getListChildAt(myList,2) as Label;
var p:Point = new Point(item.x,item.y);
p = item.localToGlobal(p);
var p2:Point = new Point(item2.x,item2.y);
p2 = item.localToGlobal(p2);
//globalLabel.text = "(Global image)x:"+p.x+",y:"+p.y;
trace(p.x,p.y,p2.x,p2.y,"(Global position)x:"+p.x+",y:"+p.y);
}
protected function myList_changeHandler(event:Event):void{
}
]]>
</fx:Script>
<s:List id="myList"
width="100%" height="100%"
labelField="firstName"
change="myList_changeHandler(event)">
<s:layout>
<s:TileLayout requestedColumnCount="4" columnWidth="80" horizontalAlign="center" verticalAlign="middle" />
</s:layout>
<s:dataProvider>
<s:ArrayCollection>
<fx:Object firstName="Bill" lastName="Smith" companyID="11233"/>
<fx:Object firstName="Dave" lastName="Jones" companyID="13455"/>
<fx:Object firstName="Mary" lastName="Davis" companyID="11543"/>
<fx:Object firstName="Debbie" lastName="Cooper" companyID="14266"/>
</s:ArrayCollection>
</s:dataProvider>
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<s:Label text="{data.lastName}"/>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
<s:VGroup >
<s:Label id="image1" text="ssss" />
<s:Button click="show()" label="show Global x、y"/>
</s:VGroup>
</s:Application>