<p>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.</p>

<p>Here's the code:</p>

<pre><code>function xmlLoaded(evt:Event):void
{   
    //do some stuff

    for(var i:int = 0; i &lt; 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 &gt; 1);

        thisProfile.profiletextholder.addChild(vScrollBar);

        //do some more stuff
    }
}
</code></pre>

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

[{'answer_id': 57197, 'author': 'Jeff Winkworth', 'author_id': 1306, 'author_profile': 'https://Stackoverflow.com/users/1306', 'pm_score': 0, 'selected': False, 'text': '<p>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?</p>\n\n<p>I have had some <em>interesting</em> experiences in the past with dynamically creating UIScrollbars at runtime.</p>\n'}, {'answer_id': 74302, 'author': 'defmeta', 'author_id': 10875, 'author_profile': 'https://Stackoverflow.com/users/10875', 'pm_score': 0, 'selected': False, 'text': '<p>In your first example have you tried putting the \n<code>vScrollBar.update();</code> \nstatement <strong>after</strong> the \n<code>addChild(vScollbar);</code> \n?</p>\n'}, {'answer_id': 74342, 'author': 'defmeta', 'author_id': 10875, 'author_profile': 'https://Stackoverflow.com/users/10875', 'pm_score': 2, 'selected': False, 'text': '<p>You might try adding the scrollbar once your textfield is initialized from a separate function similar to this:</p>\n\n<pre><code>private function assignScrollBar(tf:TextField, sb:UIScrollBar):void {\n    trace("assigning scrollbar");\n    sb.move(tf.x + tf.width, tf.y);\n    sb.setSize(15, tf.height);\n    sb.direction = ScrollBarDirection.VERTICAL;\n    sb.scrollTarget = tf;\n    addChild(sb);\n    sb.update();         \n}\n</code></pre>\n\n<p>That is how I currently doing it.</p>\n'}]
['https://Stackoverflow.com/questions/56968', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']