开发者

Accessing itemRenderer instance flash buiilder 4

开发者 https://www.devze.com 2023-01-08 19:29 出处:网络
My setup is pretty basic. I have an s:List with a custom itemRenderer and a datapro开发者_运维问答vider. What I would like to do is access the generated instances of the item renderer but I have no id

My setup is pretty basic. I have an s:List with a custom itemRenderer and a datapro开发者_运维问答vider. What I would like to do is access the generated instances of the item renderer but I have no idea how.

Here is the code for the list:

<s:List id="layersList" 
            borderVisible="false"  
            allowMultipleSelection="true" 
            contentBackgroundAlpha="0" 
            itemRenderer="renderers.LayerRenderer" 
            dataProvider="{AssetsCollection}">
     <s:layout>
    <s:VerticalLayout gap="1"  />           
     </s:layout>
<s:list>

What I would like is to access the generated renderers like:

layersList.renderers[selectedIndex] or layersList.selectedItems[0].renderer. In order to access some of its internal objects. Like in the event I would want to listen events dispatched in the renderer instance from the List's parent.

Can anyone help?


the conceptual model of Lists/ItemRenderers is that they are a representation of the items in the dataProvider. One reason for keeping this in mind is that Lists recycle their ItemRenderers in order to reduce memory footprint. This means you may have 100 items in your dataProvider, but only a small subset of those will have ItemRenderers associated with them, and some of those may not even be visible on screen or even valid any longer. There are a few ways you could approach having your ItemRenderers in your List reflect the state of the List's parent without having to directly manipulate the renderers. For instance, you could do something like this:

<s:List id="layersList" 
        borderVisible="false" 
        allowMultipleSelection="true" 
        dataProvider="{AssetsCollection}"
        contentBackgroundAlpha="0">
    <s:layout>
        <s:VerticalLayout gap="1" />      
    </s:layout>
    <s:itemRenderer>
        <fx:Component>
            <myrenderers:TestRenderer myState="{outerDocument.someState}"/>
        </fx:Component>
    </s:itemRenderer>
</s:List>

Where TestRenderer has a bindable public property called myState. And the List's parent has a bindable property called "someState". Then inside your renderer you can set some conditional logic based on the value of myState. Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消