views:

1034

answers:

5

I'm trying to attach an instance of UIScrollbar component to a dynamic text field inside of an instance of a class that is being made after some XML is loaded. The scroll bar component is getting properly attached, as the size of the slider varies depending on the amount of content in the text field, however, it won't scroll.

Here's the code:

function xmlLoaded(evt:Event):void
{   
    //do some stuff

    for(var i:int = 0; i < numProfiles; i++)
    {
     var thisProfile:profile = new profile();

     thisProfile.alpha = 0;
     thisProfile.x = 0;
     thisProfile.y = 0;
     thisProfile.name = "profile" + i;

     profilecontainer.addChild(thisProfile);

     thisProfile.profiletextholder.profilename.htmlText = profiles[i].attribute("name");
     thisProfile.profiletextholder.profiletext.htmlText = profiles[i].profiletext;

     //add scroll bar
     var vScrollBar:UIScrollBar = new UIScrollBar();
     vScrollBar.direction = ScrollBarDirection.VERTICAL;
     vScrollBar.move(thisProfile.profiletextholder.profiletext.x + thisProfile.profiletextholder.profiletext.width, thisProfile.profiletextholder.profiletext.y);
     vScrollBar.height = thisProfile.profiletextholder.profiletext.height;
     vScrollBar.scrollTarget = thisProfile.profiletextholder.profiletext;
     vScrollBar.name = "scrollbar";
     vScrollBar.update();
     vScrollBar.visible = (thisProfile.profiletextholder.profiletext.maxScrollV > 1);

     thisProfile.profiletextholder.addChild(vScrollBar);

     //do some more stuff
    }
}

I've also tried it with a UIScrollBar component within the movieclip/class itself, and it still doesn't work. Any ideas?

Thanks in advance!

A: 

Have you tried putting the UI scrollbar onto the stage, binding it to the textfield at design time, and then calling update() during the loaded event?

I have had some interesting experiences in the past with dynamically creating UIScrollbars at runtime.

Jeff Winkworth
A: 

I just got done messing around with that - I've placed an instance in the profiletextholder clip named scrollbar and changed the code like so:

thisProfile.profiletextholder.profilename.htmlText = profiles[i].attribute("name");
thisProfile.profiletextholder.profiletext.htmlText = profiles[i].profiletext;

thisProfile.profiletextholder.scrollbar.update();

Still no dice :(

I'm doing the update in a urlloader's complete event, just like the example documentation. I can't figure out what the issue is for the life of me.

Any other ideas?

A: 

In your first example have you tried putting the vScrollBar.update(); statement after the addChild(vScollbar); ?

defmeta
+1  A: 

Also, you might try adding the scrollbar once your textfield is initialized from a separate function similar to this:

   private function assignScrollBar(tf:TextField, sb:UIScrollBar):void {
        trace("assigning scrollbar");
        sb.move(tf.x + tf.width, tf.y);
        sb.setSize(15, tf.height);
     sb.direction = ScrollBarDirection.VERTICAL;
        sb.scrollTarget = tf;
        addChild(sb);
        sb.update();         
    }

That is how I currently do it.

defmeta
A: 

I have the same problem... at first I thought it was somehow breaking the link because I was moving it and resizing it on the fly, but then I got rid of the resize and it was still miss-behaving.

going to try this:

sb.move(tf.x + tf.width, tf.y); sb.setSize(15, tf.height); sb.direction = ScrollBarDirection.VERTICAL; sb.scrollTarget = tf;

failing that, I will give up and roll my own with masking, like this:

http://www.ultrashock.com/forums/actionscript/as3-scrollbar-it-works-90741.html

this was my solution: http://www.ultrashock.com/forums/actionscript/as3-scrollbar-it-works-90741.htmla little different perhaps but it got the job done.