English 中文(简体)
flash builder(flex): VScrollbar for a DataGroup, how to scroll down by default?
原标题:

i have an HGroup that contains a DataGroup with an ArrayCollection for a dataProvider.

the DataGroup has a VScrollBar attached to it.

how can i make sure that whenever new rows are added to the ArrayCollection, the dataGroup will scroll down ?

this window is gonna be used for a chat application so whenever new rows are added i need to see the new rows.

i know that i can perform the following command to scroll down: chatScrollBar.value=chatScrollbar.maximum

but what event do i need to attach to in order to run this command whenever a new row is visible ?

<s:HGroup width="100%">
 <s:DataGroup id="vertView"  
     clipAndEnableScrolling="true" width="100%" height="60"
     dataProvider="{chatMessages}">

  <s:itemRenderer>
   <fx:Component>
    <s:ItemRenderer width="100%" height="8">
     <s:states>
      <s:State name="normal" />
      <s:State name="hovered" />
     </s:states>

     <s:RichText  text="{ data }" textAlign="left" paddingLeft="2" color="black" color.hovered="blue"/>
    </s:ItemRenderer>
   </fx:Component>
  </s:itemRenderer>

  <s:layout> 
   <s:VerticalLayout useVirtualLayout="true"/> 
  </s:layout> 
 </s:DataGroup> 
 <s:VScrollBar id="chatScrollBar" viewport="{vertView}" 
      height="{vertView.height}" />

</s:HGroup>
问题回答

You have to set the verticalScrollPosition. See here or here. Or try this for a Spark List:

<s:List id="list"
            horizontalCenter="0"
            verticalCenter="0">
        <s:layout>
            <s:VerticalLayout id="vLayout" requestedRowCount="4"
                    verticalScrollPosition="{vLayout.maxScrollPosition}" />
        </s:layout>
</s:list>

Try using Scroller, I think it is as simple as:

<s:Scroller >
  <s:HGroup>
  ...
  </s:HGroup>
</s:Scroller>

You shouldn t need to hook up your own scrollbar.





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签