0

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 コンポーネントでも試しましたが、まだ機能しません。何か案は?

4

3 に答える 3

2

テキストフィールドが次のような別の関数から初期化されたら、スクロールバーを追加してみてください。

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

それが私が現在やっている方法です。

于 2008-09-16T16:40:40.413 に答える
0

UIスクロールバーをステージに配置し、デザイン時にテキストフィールドにバインドしてから、ロードされたイベント中にupdate()を呼び出してみましたか?

私は過去に、実行時にUIScrollbarを動的に作成するという興味深い経験をしました。

于 2008-09-11T17:51:51.687 に答える
0

vScrollBar.update(); 最初の例では、ステートメントを ? のに入れてみ ました addChild(vScollbar); か?

于 2008-09-16T16:36:12.607 に答える