views:

264

answers:

1

I'm writing a chat client using Flex.

The basis for the chat window is a canvas. I've got that showing, but how do I make it scroll up? I want to clip the window so only the last 15 lines are shown.

This doesn't appear to be working (nothing moves):

<mx:Canvas id="canvas" width="300" height="3000" horizontalScrollPolicy="off" verticalScrollPolicy="on" creationComplete="myinit()">
    <mx:Label text="HI" x="10" y="100"/>
</mx:Canvas>

Shouldn't this scroll the canvas every time it's called?:

canvas.verticalScrollPosition += 10;

A: 

You should change the verticalScrollPosition of the parent container. Such as

<mx:Canvas id="canvas" width="300" height="300"
           horizontalScrollPolicy="off" verticalScrollPolicy="on"
           creationComplete="myinit()">
    <mx:Canvas id="canvas" width="300" height="3000">
        <mx:Label text="HI" x="10" y="100"/>
    </mx:Canvas>
</mx:Canvas>

Now

canvas.verticalScrollPosition += 10;

should work.

tehmou
Ah, duh! That makes sense. One problem, though, when I try to add an 'id' attribute to the outer canvas I get this:id attribute is not allowed on the root tag of a component.How do you get around that? Thanks for your help.
Pete Alvin