0

我想获取标签元素在列表中的位置,

但我明白了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>
4

2 回答 2

0
            var item:UIComponent = getListChildAt(myList,2);
            var item2:UIComponent = getListChildAt(myList,0);
            p = new Point(item.parent.x,item.parent.y);
            p = myList.localToGlobal(p);
            p2 = new Point(item2.parent.x,item2.parent.y);
            p2 = myList.localToGlobal(p2);

            var a:Rectangle =  item2.getBounds(root);
            trace(a.x);
于 2012-04-24T08:06:30.803 回答
0
<?xml version="1.0" encoding="utf-8"?>

        protected function getListChildAt(part:List,n:int):UIComponent {
            var child:UIComponent = part.dataGroup.getChildAt(n) as UIComponent;
            var child_1:UIComponent =  child.getChildAt(0) as UIComponent;
            trace(child_1.parent == child)
            return child_1 ;
        }

        protected function show():void
        {
            var item:UIComponent = getListChildAt(myList,2);
            var item2:UIComponent = getListChildAt(myList,0);
            p = new Point(item.parent.x,item.parent.y);
            p = myList.localToGlobal(p);
            p2 = new Point(item2.parent.x,item2.parent.y);
            p2 = myList.localToGlobal(p2);


            mover.play()
        }
        protected function myList_changeHandler(event:Event):void{

        }





    ]]>
</fx:Script>
<s:List id="myList" x="40" y="55" width="400" height="100" change="myList_changeHandler(event)"
        labelField="firstName">

    <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}" width="70" height="30"/>
            </s:ItemRenderer>
        </fx:Component>
    </s:itemRenderer>
</s:List>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <s:Animate id="mover" target="{button}" duration="1000">
        <s:SimpleMotionPath property="x" valueFrom="{p.x}" valueTo="{p2.x}"/>
        <s:SimpleMotionPath property="y" valueFrom="{p.y}" valueTo="{p2.y}"/>
    </s:Animate>
</fx:Declarations>
<s:Button id="button"  click="mover.play()" label="" width="70"/>

<s:Label id="image1" x="0" y="0" text="ssss" backgroundColor="red"/>
<s:Button x="27" y="100" label="show Global x、y" click="show()"/>

于 2012-04-24T07:54:31.357 回答