Flash AS3:如何使滚动条对动态文本字段移动做出反应?
我一直在寻找教程和答案,但找不到我要找的东西。我正在将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将scrollHandler 计算替换为您的计算。
Replace the scrollHandler calculations with yours.