Trouble with scrolling a UIScrollBar component within a class
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?
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 doing it.
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.
In your first example have you tried putting the vScrollBar.update();
statement after the addChild(vScollbar);
?
上一篇: 组件检查器,属性始终为空?