UIScrollbar组件在flash cs4中不起作用

时间:2012-01-18 01:37:53

标签: flash actionscript-3 flash-cs4

好的,所以我有这个名为logtxt的动态文本框,我附加了一个UIScrollbar。它工作,但只有我通过键入/粘贴到文本框中添加它。当我通过代码添加文本时,我需要它工作。 (它通过组件检查器正确链接)

2 个答案:

答案 0 :(得分:0)

  

“当我通过代码添加文本时,我需要它才能工作。”

你可以通过代码完成所有这一切没有问题,例如把它放在你的主时间轴上;

import fl.controls.TextArea;

var myText:String = "Here is some text, notice how there will a automatigical scroll bar when needed :)";

var textarea_comp:TextArea = new TextArea();
textarea_comp.text = myText;
textarea_comp.height = 60;
addChild ( textarea_comp );

如果您想对现有的文本字段执行此操作,请将此代码放在此代码所在的上下文中。

logtxt.text = "default custom text"

答案 1 :(得分:0)

我制作了动画片段drag_mc和track_mc,并将它们放在名为scroll_mc的影片剪辑中。然后我有一个用于制作滚动条的课程:

package {
    import flash.display.Stage;
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.geom.Rectangle;

class MakeScrollBar {
    private var host_mc:MovieClip;
    private var call_back:Function;

    private var drag_mc:MovieClip;
    private var track_mc:MovieClip;

    private var scroll_rect:Rectangle;
    private var upper_limit:Number;
    private var range:Number;

    public function MakeScrollBar( _mc:MovieClip, cb:Function ) {
        host_mc = _mc;
        call_back = cb;

        drag_mc = host_mc.drag_mc; // 
        drag_mc.buttonMode = true;
        drag_mc.mouseChildren = false
        drag_mc.addEventListener( MouseEvent.MOUSE_DOWN, press_drag );
        track_mc = host_mc.track_mc;
        track_mc.buttonMode = true;
        track_mc.mouseChildren = false
        track_mc.addEventListener( MouseEvent.CLICK, click_track );

        set_limits();

    }

    private function press_drag( event:MouseEvent ):void {
        drag_mc.stage.addEventListener( MouseEvent.MOUSE_UP, release_drag, false, 0, true );

        drag_mc.startDrag( false, scroll_rect );
        drag_mc.addEventListener( Event.ENTER_FRAME, drag );
    }

    private function release_drag( event:MouseEvent ):void {
        drag_mc.removeEventListener( Event.ENTER_FRAME, drag );
        drag_mc.stage.removeEventListener( MouseEvent.MOUSE_UP, release_drag );
        drag_mc.stopDrag();
    }

    private function click_track( event:MouseEvent ):void {
        trace( "Click track" );
    }

    private function set_limits():void {
        scroll_rect = new Rectangle( track_mc.x, track_mc.y, 0, track_mc.height - drag_mc.height );
        upper_limit = track_mc.y;
        range = track_mc.height - drag_mc.height;
    }

    private function drag( event:Event ):void {
        var p = ( drag_mc.y - track_mc.y ) / range;
        call_back( p );
    }
}
}

和文档类

package {
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.events.MouseEvent;

    public class ScrollBarAS3 extends Sprite {
        public var my_scrollbar:MakeScrollBar;

        public function ScrollBarAS3() {
            my_scrollbar = new MakeScrollBar( scroll_mc, scroll_text );
        }

        public function scroll_text( n:Number ) {
            scroll_txt.scrollV = Math.round( ( scroll_txt.maxScrollV - 1 ) * n ) + 1;
        }
    }
}

scroll_txt是文本框

http://www.webdevils.com/2007/10/13/as3-version-of-scrollbar-class/

获得