【问题标题】:how to get the label element's position which in the list, about flex mobile如何获取列表中标签元素的位置,关于flex mobile
【发布时间】:2012-04-24 06:31:55
【问题描述】:

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

但我得到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>

【问题讨论】:

  • 我不明白你在问什么;我不明白您发布的两个答案是如何解决您的问题的。

标签: apache-flex list mobile position itemrenderer


【解决方案1】:
<?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()"/>

【讨论】:

    【解决方案2】:
                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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-11
      • 2011-08-09
      • 1970-01-01
      • 2023-03-10
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多