Page 1 of 1

flash scrollbar, autoscroll to bottom

Posted: Thu May 31, 2007 11:13 pm
by s.dot
A guy on here recently asked a question about a php socket chat with a flash GUI. After we asked him to show some of his code, he linked to this tutorial: http://www.kirupa.com/developer/flash8/ ... flash8.htm

Awesome tutorial!

I now have a working chat room using php sockets with a simple flash GUI. Now I'm going to tear this program apart and add in a bunch of features and connect it to my web sites database for an ultimate chatting experience.

However, I have a problem already, on my first obstacle! I can't figure out how to get the vertical scroll bar to scroll when a new message is sent.

I read through the flash help and there are so many options I could use. I don't know which one I want. This looked kind of promising:

Code: Select all

/**
 Requires:
  - UIScrollBar component in library
*/
// Create the text field.
this.createTextField("my_txt", 10, 10, 20, 200, 100);
my_txt.wordWrap = false;

my_txt.text = "Mary had a little lamb whose fleece " + 
"was white as snow and everywhere that Mary went the " +
"lamb was sure to go."
// Create scroll bar.
this.createClassObject(mx.controls.UIScrollBar, "my_sb", 20);
my_sb.horizontal = true;

// Set the target text field for the scroll bar.
my_sb.setScrollTarget(my_txt);
// Size it to match the text field.
my_sb.setSize(my_txt._width, 16);

// Move it to the bottom of the text field.
my_sb.move(my_txt._x, my_txt._y + my_txt._height);
I believe that does what I want to do, only horizontally, although I'm not sure.

With all that said, how can I get the scroll bar to scroll down vertical (equivalant to javascripts scrollIntoView(false);), or what methods/proprties of the UIObject should I be looking at?[/syntax]

Posted: Fri Jun 01, 2007 6:42 am
by superdezign
ActionScript isn't client-side...

I believe that the TextField class has a maxscroll property.

Code: Select all

chat_txt.onChanged = function()
{
    this.scroll = this.maxscroll;
}
Looking at this code (if it works), it would seem to be the same code that YouTube's Streams use (or used the last time I was there). They forced your box to scroll down, even if you were scrolling up, so you'd never be able to see the whole conversation. Maybe you could try:

Code: Select all

var lastScroll = chat_txt.maxscroll;
chat_txt.onChanged = function()
{
    if(this.scroll == lastScroll)
        this.scroll = this.maxscroll;
    
    lastScroll = this.maxscroll;
}
That's assuming that simply setting the scroll property will cause the box to scroll.

Posted: Fri Jun 01, 2007 7:11 am
by feyd
ActionScript runs in Flash, Flash runs in the browser not the server. The browser is client-side. ;)

Posted: Fri Jun 01, 2007 7:15 am
by superdezign
feyd wrote:ActionScript runs in Flash, Flash runs in the browser not the server. The browser is client-side. ;)
... Yeah, it's not server-side... But I just can't see it being client-side since the code is hidden from the user. Then again.... I guess the criteria has nothing to do with the visibility of the code.