【问题标题】:Trouble with scrolling a UIScrollBar component within a class在类中滚动 UIScrollBar 组件时出现问题
【发布时间】:2010-09-08 14:09:05
【问题描述】:

我正在尝试将 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
    }
}

我还尝试在影片剪辑/类本身中使用 UIScrollBar 组件,但它仍然无法正常工作。有什么想法吗?

【问题讨论】:

    标签: flash actionscript-3 actionscript


    【解决方案1】:

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

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

    这就是我目前的做法。

    【讨论】:

      【解决方案2】:

      在您的第一个示例中,您是否尝试过将 vScrollBar.update(); 声明之后 addChild(vScollbar); ?

      【讨论】:

        【解决方案3】:

        您是否尝试过将 UI 滚动条放到舞台上,在设计时将其绑定到文本字段,然后在加载事件期间调用 update()?

        我过去在运行时动态创建 UIScrollbars 方面有过一些有趣的经验。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-11-04
          • 1970-01-01
          • 2016-10-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多