在类中滚动UIScrollBar组件时遇到问题

我试图将一个UIScrollbar组件的实例附加到加载一些XML后正在创建的类的实例内部的动态文本字段。 滚动条组件正在正确连接,因为滑块的大小取决于文本字段中的内容数量,但它不会滚动。

代码如下:

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
    }
}

我也尝试过在movieclip / class中使用UIScrollBar组件,但它仍然不起作用。 有任何想法吗?


您可以尝试添加滚动条,一旦您的文本字段从类似于以下的单独函数初始化:

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();         
}

这就是我目前的做法。


你有没有尝试把UI滚动条放到舞台上,在设计时将它绑定到文本框,然后在加载事件期间调用update()?

在过去,我在运行时动态地创建了UIScrollbars,我有过一些有趣的经历。


在你的第一个例子中,你是否尝试过放置vScrollBar.update(); addChild(vScollbar); 之后的语句addChild(vScollbar);

链接地址: http://www.djcxy.com/p/17839.html

上一篇: Trouble with scrolling a UIScrollBar component within a class

下一篇: What is a proper way to upgrade from Flash CS4 project to Flash CS5?