Flex 4 处理深度

发布于 2024-09-09 22:24:20 字数 1563 浏览 0 评论 0原文

我在 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 中的所有项目都按分配给它们的“深度”顺序显示。

我该怎么做?

I have a code in Flex 4 like this

<!-- 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>

Mainly it's a MX:Canvas that has inside it reapeaters for multiple custom components I created. Most of these custom components are like this:

   <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)" >

Everything works fine (x,y,width,height,rotation) except for depth!

it seems that regardless what the number is it shows as the order it was rendered in the parent container. (MX:Canvas)!

What I want to acheive is that relative to each others, all the items in the mx:Canvas shows in the order of "depth" assigned to them.

How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£烟消云散 2024-09-16 22:24:20

您正在使用中继器;这本质上是一个循环。

听起来您好像要求循环遍历项目,但以不同的顺序处理这些项目。这是正确的吗?

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

我的第二个建议是不要使用中继器。由于渲染器回收,基于列表的类将为您提供更好的性能。

如果您确实需要一次创建所有子项,我的第三个建议是您转向 ActionScript 实现,这将使您能够更精细地控制创建事物的方式和时间。

每次我使用中继器时我都很不高兴。


以下是有关 Flex 的列表和 itemRenderers 的一些信息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 选项。

如果您想使用基于 ATA 的不同渲染器,请考虑使用 itemRenderer函数

You're using a repeater; which is, in essence, a loop.

It sounds like you're asking to loop over items, but process those items in a different order. Is that correct?

My first recommendation would be that you look into ways to sort your dataProvider items by depth before the repeater 'runs'.

My second recommendation is that you don't use a repeater. A List based class will give you better performance due to renderer recycling.

If you really need to create all children at once, my third recommendation is that you move to an ActionScript implementation which will give you lots more granular control over how and when things are created.

Everytime I've used a repeater I've been unhappy.


Here is some info on lists and itemRenderers with Flex 4.

This is a rough estimate of how I might modify this sample to use a list instead of a repeater:

    <!-- 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>

An itemRenderer may be something like this:

<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>

The list will determine the width, x, and y positions of the renderer. In most cases it will also determine the height; although the Flex 3 List has a variableRowHeight option.

If you want to use a different renderer based ond ata, look into using an itemRendererFunction

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文