Flash AS3:如何使滚动条对动态文本字段移动做出反应?

发布于 2024-09-04 04:28:17 字数 1205 浏览 4 评论 0原文

我一直在寻找教程和答案,但找不到我要找的东西。我正在将 html 文本加载到动态文本字段中,并且有一个滚动条使用下面的代码控制滚动。我想做的还包括添加向上/向下滚动按钮,并使滚动条相对于文本滚动移动。我本来打算使用“tracklistingtext.scrollV -- ”作为滚动按钮,但现在滚动条无法识别文本移动。我需要做什么才能让滚动条监听文本滚动位置?

var listTextreq:URLRequest=new URLRequest("tracklist.txt");
var listTextLoader:URLLoader = new URLLoader();
var bounds:Rectangle=new Rectangle(scrollMC.x,scrollMC.y,0,300);
var scrolling:Boolean=false;

function fileLoaded(event:Event):void {
 tracklistingtext.htmlText=listTextLoader.data;
 tracklistingtext.multiline=true;
 tracklistingtext.wordWrap=true;
 scrollMC.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
 stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
 addEventListener (Event.ENTER_FRAME, enterHandler);

}

listTextLoader.addEventListener(Event.COMPLETE, fileLoaded);
listTextLoader.load(listTextreq);

function startScroll(e:Event):void {
 scrolling=true;
 scrollMC.startDrag(false,bounds);
}

function stopScroll(e:Event):void {
 scrolling=false;
 scrollMC.stopDrag();
}

function enterHandler (e:Event):void {
 if (scrolling == true) {
  tracklistingtext.scrollV = Math.round(((scrollMC.y - bounds.y)/300)*tracklistingtext.maxScrollV);
 }
}

非常感谢任何帮助。

I've been looking for a tutorial and answer to this for a while but can't find what I'm looking for. I am loading html text into a dynamic textfield, and I have a scrollbar controlling the scroll using the code below. What I want to do is also add scroll up/down buttons and have the scroll bar move in relation to the text scroll. I was just going to use "tracklistingtext.scrollV -- " for the scroll buttons, but right now the scroll bar doesn't recognize the text movement. What do I need to do to get the scroll bar to listen to the text scroll position?

var listTextreq:URLRequest=new URLRequest("tracklist.txt");
var listTextLoader:URLLoader = new URLLoader();
var bounds:Rectangle=new Rectangle(scrollMC.x,scrollMC.y,0,300);
var scrolling:Boolean=false;

function fileLoaded(event:Event):void {
 tracklistingtext.htmlText=listTextLoader.data;
 tracklistingtext.multiline=true;
 tracklistingtext.wordWrap=true;
 scrollMC.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
 stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
 addEventListener (Event.ENTER_FRAME, enterHandler);

}

listTextLoader.addEventListener(Event.COMPLETE, fileLoaded);
listTextLoader.load(listTextreq);

function startScroll(e:Event):void {
 scrolling=true;
 scrollMC.startDrag(false,bounds);
}

function stopScroll(e:Event):void {
 scrolling=false;
 scrollMC.stopDrag();
}

function enterHandler (e:Event):void {
 if (scrolling == true) {
  tracklistingtext.scrollV = Math.round(((scrollMC.y - bounds.y)/300)*tracklistingtext.maxScrollV);
 }
}

Any help is greatly appreciated.

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

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

发布评论

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

评论(1

无人问我粥可暖 2024-09-11 04:28:17

将scrollHandler 计算替换为您的计算。

//...

function fileLoaded(event:Event):void {
    tracklistingtext.htmlText=listTextLoader.data;
    tracklistingtext.multiline=true;
    tracklistingtext.wordWrap=true;
    scrollMC.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
    stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
    addEventListener (Event.ENTER_FRAME, enterHandler);
    /* !!! */ tracklistingtext.addEventListener(Event.SCROLL, scrollHandler);
}

//...

function scrollHandler(event:Event):void {
    scrollMC.y = (tracklistingtext.scrollV / tracklistingtext.maxScrollV) * bounds.height + bounds.y;
}

Replace the scrollHandler calculations with yours.

//...

function fileLoaded(event:Event):void {
    tracklistingtext.htmlText=listTextLoader.data;
    tracklistingtext.multiline=true;
    tracklistingtext.wordWrap=true;
    scrollMC.addEventListener(MouseEvent.MOUSE_DOWN, startScroll);
    stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
    addEventListener (Event.ENTER_FRAME, enterHandler);
    /* !!! */ tracklistingtext.addEventListener(Event.SCROLL, scrollHandler);
}

//...

function scrollHandler(event:Event):void {
    scrollMC.y = (tracklistingtext.scrollV / tracklistingtext.maxScrollV) * bounds.height + bounds.y;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文