代码之家  ›  专栏  ›  技术社区  ›  Tam

Flex 4的处理深度

  •  2
  • Tam  · 技术社区  · 16 年前

    我在Flex 4中有这样一个代码

    <!-- START >>> middle part: items -->
    <mx:Canvas id="itemContainer"
               width="100%"
               height="100%">
        <!-- START >>> Items Display on the page -->
        <mx:Repeater id="richTextReapeater" 
                     dataProvider="{_model.current_day.richTextNotes}">
            <components:RichTextNoteDisplay theNote="{richTextReapeater.currentItem}" />    
        </mx:Repeater>
        <mx:Repeater id="postItReapeater" 
                     dataProvider="{_model.current_day.positNotes}">
                <components:PostItNoteDisplay theNote="{postItReapeater.currentItem}"  />   
        </mx:Repeater>
        ......
    </mx:Canvas>
    

    它主要是一个MX:Canvas,里面有我创建的多个自定义组件的重复器。大多数自定义组件如下所示:

       <s:SkinnableContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
                              xmlns:s="library://ns.adobe.com/flex/spark"
                              xmlns:mx="library://ns.adobe.com/flex/mx"
                              x="{theNote.x}"
                              y="{theNote.y}"
                              width="{theNote.width}"
                              height="{theNote.height}"
                              depth="{theNote.depth}"
                              rotation="{theNote.rotation}"
    creationComplete="skinnablecontainer1_creationCompleteHandler(event)" >
    

    除了深度以外,一切都很好(x,y,宽度,高度,旋转)!

    似乎不管数字是多少,它都显示为在父容器中呈现的顺序(MX:画布)!

    我想了解的是,相对于彼此,mx:Canvas中的所有项目都是按照分配给它们的“深度”顺序显示的。

    我该怎么做?

    1 回复  |  直到 16 年前
        1
  •  1
  •   JeffryHouser    16 年前

    听起来像是要求循环处理项目,但处理这些项目的顺序不同。对吗?

    我的第一个建议是,在中继器“运行”之前,研究按深度对dataProvider项进行排序的方法。

    我的第二个建议是你不要用中继器。一个基于列表的类将给你更好的性能由于渲染器的回收。

    每次我用中继器我都不开心。


    这里有一些关于 lists and itemRenderers 使用Flex 4。

        <!-- START >>> middle part: items -->
        <mx:Canvas id="itemContainer"
                   width="100%"
                   height="100%">
            <!-- START >>> Items Display on the page -->
            <s:List id="richTextList" 
                         dataProvider="{_model.current_day.richTextNotes}"
                         itemRenderer="com.something.myComponent">
            </s:List>
        </mx:Canvas>
    

    itemRenderer可能是这样的:

    <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:mx="library://ns.adobe.com/flex/mx" 
        xmlns:s="library://ns.adobe.com/flex/spark">
        <s:SkinnableContainer rotation="{data.rotation}"
        creationComplete="skinnablecontainer1_creationCompleteHandler(event)" />
    </s:ItemRenderer>
    

    该列表将确定渲染器的宽度、x和y位置。在大多数情况下,它还将决定高度;尽管Flex 3列表有一个 variableRowHeight 选项。

    itemRendererFunction