【问题标题】:Obtaining a HGroup subcomponent that it is in view of a Scroller container Adobe Flex 4.5在 Scroller 容器 Adob​​e Flex 4.5 中获取它所在的 HGroup 子组件
【发布时间】:2012-02-24 15:40:00
【问题描述】:

我已经围绕一个 HGroup 标签设置了一个 Scroller 容器。 Scroller 设置为一次仅显示一个标签。我想要做的是确定单击按钮时滚动器视图中的标签。我已经搜索了有关 Scrollers 和 HGroups 的参考资料,但无法制定程序化策略来确定该组的哪些元素是可见的。

滚动代码供参考:

<local:Scroller id="imageViewer" includeIn="startState" left="411" right="411" top="241"
                    bottom="356" depth="2"> 
    <s:HGroup id="imageGroup" gap="0" width="100%" height="100%"> 
        <s:Label id="vin1337" width="201" height="104" color="white" fontSize="30"
                 text="Vehicle ID:1337" textAlign="center" verticalAlign="middle"/>
        <s:Label id="vin2567" width="199" height="104" color="white" fontSize="30"
                 text="Vehicle ID:2567" textAlign="center" verticalAlign="middle"/>
        <s:Label id="vin9456" width="199" height="104" color="white" fontSize="30"
                 text="Vehicle ID:9456" textAlign="center" verticalAlign="middle"/>
    </s:HGroup> 
</local:Scroller>

最终这些标签将是图像,但目前使用标签作为概念证明。

任何帮助将不胜感激,感谢您的阅读。

编辑: 因此,在使用 lastIndexInView 实现方法后,我不断收到“TypeError:错误 #1009:无法访问空对象引用的属性或方法”。在“vehicleID.text = Label(lObj).text;”这一行上。下面是涉及的代码:

功能:

        protected function idSelect_clickHandler(event:MouseEvent):void
        {
            var hLay:HorizontalLayout = imageGroup.layout as HorizontalLayout;
            var lIndex:int = hLay.lastIndexInView;
            var lObj:Object = imageGroup.getElementAt(lIndex);

            vehicleID.text = Label(lObj).text;

            currentState="selectedState";
        }

组件:

<local:SnapScroller id="imageViewer" includeIn="startState" left="411" right="411" top="241"
                    bottom="356" depth="2"> 
    <s:HGroup id="imageGroup" gap="0" width="100%" height="100%"> 
        <s:Label id="vin1337" width="201" height="104" color="white" fontSize="30"
                 text="Vehicle ID:1337" textAlign="center" verticalAlign="middle"/>
        <s:Label id="vin2567" width="199" height="104" color="white" fontSize="30"
                 text="Vehicle ID:2567" textAlign="center" verticalAlign="middle"/>
        <s:Label id="vin9456" width="199" height="104" color="white" fontSize="30"
                 text="Vehicle ID:9456" textAlign="center" verticalAlign="middle"/>
    </s:HGroup> 
</local:SnapScroller>

<s:Button id="idSelect" includeIn="startState" x="367" y="608" width="290" height="67"
          label="Select" click="idSelect_clickHandler(event)" color="#00008F" fontSize="24"/>

<s:Label id="vehicleID" includeIn="selectedState" x="425" y="453" color="#00008F" fontSize="24"
         text="Vehicle ID: ____"/>

【问题讨论】:

    标签: actionscript-3 apache-flex flex4 flash-builder flex-spark


    【解决方案1】:

    我认为这应该回答你的问题http://blog.flexexamples.com/2009/10/31/determining-how-much-of-an-item-is-visible-in-a-scrolling-vgroup-container-in-flex-4/

    基本上,布局具有 firstIndexInView 和 lastIndexInView 属性,它们会告诉您哪些项目是可见的。

    【讨论】:

    • 这清楚地列出了所有内容,这正是我想要的。
    • 我已经更新了我的问题,包括您的建议以及它产生的新问题
    【解决方案2】:

    我遇到的第二个问题是由于我在实际初始化车辆ID 组件之前尝试访问它。换句话说,我试图更改一个不包含在当前状态中但实际上是下一个状态的成员的元素。

    通过先改变状态,然后分配标签来解决它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 2011-12-14
      相关资源
      最近更新 更多