使用 ActionScript 3.0 的软滚动

发布于 2024-08-17 08:20:28 字数 1197 浏览 5 评论 0原文

我是一个尝试使用 Flash 开发我的第一个网站的菜鸟。我制作了一些滚动条,但它们并不平滑...

我使用的代码是:

const scrollUpper:int = -151;
const scrollLower:int = 366;
const scrollRange:int = scrollLower - scrollUpper;
var dragBounds:Rectangle = new Rectangle(scroller_mc.x, scrollUpper, 0, scrollRange);

var viewableHeight:int = 545;
var textUpper:int = text_mc.y;
var textLower:int = textUpper + text_mc.height;
var textRange:int = text_mc.height - viewableHeight;

scroller_mc.addEventListener(MouseEvent.MOUSE_DOWN, startScrolling);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling);
stage.addEventListener(Event.MOUSE_LEAVE, stopScrolling);
stage.addEventListener(Event.DEACTIVATE, stopScrolling);

function scroll(e:Event = null){
const pctMoved:Number = 1 - (dragBounds.bottom - scroller_mc.y) / dragBounds.height;
text_mc.y = textUpper - (pctMoved * textRange);
}

function startScrolling(event:MouseEvent):void{
addEventListener(Event.ENTER_FRAME, scroll);
scroller_mc.startDrag(true, dragBounds);
}

function stopScrolling(event:Event = null):void{
removeEventListener(Event.ENTER_FRAME, scroll);
scroller_mc.stopDrag();
}

滚动条可以工作,但它们可以非常平滑!请提前原谅一些英文错误,好吗?

谢谢

马库斯

I'm a noob trying to develop my first site with Flash. I made some scrollers, but they aren't smooth...

The code I used was:

const scrollUpper:int = -151;
const scrollLower:int = 366;
const scrollRange:int = scrollLower - scrollUpper;
var dragBounds:Rectangle = new Rectangle(scroller_mc.x, scrollUpper, 0, scrollRange);

var viewableHeight:int = 545;
var textUpper:int = text_mc.y;
var textLower:int = textUpper + text_mc.height;
var textRange:int = text_mc.height - viewableHeight;

scroller_mc.addEventListener(MouseEvent.MOUSE_DOWN, startScrolling);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScrolling);
stage.addEventListener(Event.MOUSE_LEAVE, stopScrolling);
stage.addEventListener(Event.DEACTIVATE, stopScrolling);

function scroll(e:Event = null){
const pctMoved:Number = 1 - (dragBounds.bottom - scroller_mc.y) / dragBounds.height;
text_mc.y = textUpper - (pctMoved * textRange);
}

function startScrolling(event:MouseEvent):void{
addEventListener(Event.ENTER_FRAME, scroll);
scroller_mc.startDrag(true, dragBounds);
}

function stopScrolling(event:Event = null):void{
removeEventListener(Event.ENTER_FRAME, scroll);
scroller_mc.stopDrag();
}

The scrollers works, but they could be so much smooth! In advance, please excuse some English error, ok?

Thanks

Marcus

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

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

发布评论

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

评论(2

锦上情书 2024-08-24 08:20:28

检查你的帧速率。如果它较低(例如 12 fps),那么将其增加到 30 或 60 fps 可能会有所帮助。

否则,您可能会查看在每个 ENTER_FRAME 事件上调用的scroll() 函数。那有什么作用?

Check your frame rate. If it's low (like 12 fps) then increasing it to 30 or 60 fps might help.

Else you might look into the scroll() function that is called on every ENTER_FRAME event. What does that do?

在梵高的星空下 2024-08-24 08:20:28

你应该给出“event.updateAfterEvent();”在你的滚动事件中,这将忽略你的帧速率,并在事件完成后立即更新显示

--Andy

You should give "event.updateAfterEvent();" in you Scroll event, this will ignore your framerate, and update the display straight after the event is comeplete

--Andy

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