UIScrollbar 组件在 flash cs4 中不起作用

发布于 2024-12-27 16:46:52 字数 115 浏览 0 评论 0原文

好的,我有一个名为 logtxt 的动态文本框,并且附加了一个 UIScrollbar。它有效,但前提是我通过将其键入/粘贴到文本框中来添加它。当我通过代码添加文本时,我需要它才能工作。 (它通过组件检查器正确链接)

Ok so i have this dyanamic textbox called logtxt and i have a UIScrollbar attached to it. It works, but only if i add it through typing/pasting it into the textbox. I need it to work when i add the text through the code. (it is linked correctly through the components inspector)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小情绪 2025-01-03 16:46:52

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

您可以通过代码完成这一切,没有问题,例如将其放在您的主时间轴上;

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"

"I need it to work when i add the text through the code."

You can do this all through code no problem, for example put this on your main timeline;

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

If you want to do this with your existing textfield, put this on this code in a place that is in context where it is located.

logtxt.text = "default custom text"
筱果果 2025-01-03 16:46:52

我制作了影片剪辑“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/

I made the movieclips drag_mc and track_mc and put them in a movie clip called scroll_mc. Then i have a class for making the scroll bar:

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

and a document class

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 is the textbox

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文