ActionScript 3.0 滑块在滑动开始时不继续

发布于 2024-10-21 17:52:27 字数 2462 浏览 5 评论 0原文

我制作了一个滑块来搜索我的动作脚本视频。 如果你能看到我正在做的事情,也许你会更好地理解: http://www.stevevo.sin.khk.be/Website%202SDesign/->这是我正在构建的网站正在运行的测试服务器的链接。您会在中心看到巨大的横幅,将其翻转,您会看到一个滑块和一个暂停/开始按钮。 除了一件小事之外,滑块工作得很好。当您将滑块拖动到最左边时,actionScript 3.0 将再次开始播放影片(我假设),现在向右拖动而不会出现中断,并且滑块不会像他应该的那样向右移动(所有操作都在一次拖动中)。

为什么不能先滑到起点然后继续滑?

我的代码:

非常简单。你开始拖动,矩形就是dragRestriction。电影停止。正在拖动 = true。

SearchBarSlider.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

function fl_ClickToDrag(event:MouseEvent):void
{
    var rect:Rectangle = new Rectangle(SearchBar.x + 3, 
                       SearchBar.y, 
                       SearchBar.width - 10, 
                       0);
    SearchBarSlider.startDrag(false, rect);
stop();
    isDraging = true;
}

又简单又容易。拖动停止。电影再次开始播放。正在拖动= false;

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

function fl_ReleaseToDrop(event:MouseEvent):void
{
    SearchBarSlider.stopDrag();
    play();
    isDraging = false;
}

当鼠标移动拖动时,滑块的 x 位置将转换为合适的帧数。在这 3 个部分之间可应用其他长度。

stage.addEventListener(MouseEvent.MOUSE_MOVE, fl_Drag);

function fl_Drag(event:MouseEvent):void
{
    if(isDraging == true) {
        if(SearchBarSlider.x - (SearchBar.x + 3) < 20){
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3)) / 20) * 320));
        } else if(SearchBarSlider.x - SearchBar.x + 3 >= 20 && SearchBarSlider.x - SearchBar.x + 3 < 40){
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 20) / 20) * 365) + 365);
        } else {
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 40) / 20) * 465) + 685);
        }
    }
}

不拖动时,此事件在每一帧发生。但不是将滑块的 x 位置转换为帧,而是将帧转换为滑块的 x 位置。

stage.addEventListener(Event.ENTER_FRAME, fl_frameEvent);

function fl_frameEvent(e:Event):void
{
    if(isDraging == false) {
        if(currentFrame < 365){
            SearchBarSlider.x = SearchBar.x + 3 + Math.round((currentFrame / 365) * 20);
        } else if(currentFrame >= 365 && currentFrame < 685){
            SearchBarSlider.x = SearchBar.x + 23 + Math.round(((currentFrame - 365) / 320) * 20);
        } else {
            SearchBarSlider.x = SearchBar.x + 43 + Math.round(((currentFrame - 685) / 465) * 20);
        }
    }
}

I made a slider to search trough my actionscript video.
Maybe you'll understand better if you can see what i'm working on:
http://www.stevevo.sin.khk.be/Website%202SDesign/ -> this is the link of the testserver where the website i'm building is running on. You'll see the huge banner in the center, rollover it an you'll see a slider and a pause/start button.
The slider works great exept for 1 little thing. When you drag the slider to the utter left actionScript 3.0 will start the movie again (i asume), now drag to the right without interuptions and the slider won't move to the right as he should (all in one drag).

Why ain't it possible to first slide to the start and then continue sliding?

MY CODE:

very simple. You start dragging, the rectangle is the dragRestriction. The Movie stops. isDragging = true.

SearchBarSlider.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

function fl_ClickToDrag(event:MouseEvent):void
{
    var rect:Rectangle = new Rectangle(SearchBar.x + 3, 
                       SearchBar.y, 
                       SearchBar.width - 10, 
                       0);
    SearchBarSlider.startDrag(false, rect);
stop();
    isDraging = true;
}

Again easy peasy. Drag stops. Movie starts to play again. isdragging = false;

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

function fl_ReleaseToDrop(event:MouseEvent):void
{
    SearchBarSlider.stopDrag();
    play();
    isDraging = false;
}

When the mouse moves when dragging the x-position of the slider will be converted to the right amount of frames. In between the 3 parts other lengths aply.

stage.addEventListener(MouseEvent.MOUSE_MOVE, fl_Drag);

function fl_Drag(event:MouseEvent):void
{
    if(isDraging == true) {
        if(SearchBarSlider.x - (SearchBar.x + 3) < 20){
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3)) / 20) * 320));
        } else if(SearchBarSlider.x - SearchBar.x + 3 >= 20 && SearchBarSlider.x - SearchBar.x + 3 < 40){
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 20) / 20) * 365) + 365);
        } else {
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 40) / 20) * 465) + 685);
        }
    }
}

This event accurs at every frame when not dragging. But instead of converting the x-position of the slider to frames this will convert frames to x-positon of the slider.

stage.addEventListener(Event.ENTER_FRAME, fl_frameEvent);

function fl_frameEvent(e:Event):void
{
    if(isDraging == false) {
        if(currentFrame < 365){
            SearchBarSlider.x = SearchBar.x + 3 + Math.round((currentFrame / 365) * 20);
        } else if(currentFrame >= 365 && currentFrame < 685){
            SearchBarSlider.x = SearchBar.x + 23 + Math.round(((currentFrame - 365) / 320) * 20);
        } else {
            SearchBarSlider.x = SearchBar.x + 43 + Math.round(((currentFrame - 685) / 465) * 20);
        }
    }
}

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

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

发布评论

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

评论(2

折戟 2024-10-28 17:52:27

拖动时第二个功能真的不会发生吗?您是否将其删除,或者同时运行?我认为你的 Enter_frame 函数和 mouse_move 函数正在互相争斗。在你的拖动函数中添加这个:

stage.removeEventListener(Event.ENTER_FRAME, fl_frameEvent);

在你的放置函数中添加这个:

stage.addEventListener(Event.ENTER_FRAME, fl_frameEvent);

另一种解决方法,我注意到如果你在滑块上放大,如果你向左移动 99.9%,但没有完全对齐,它按预期工作,因此您只需调整可拖动矩形即可在左侧留下一个很小的空间。

SearchBar.x + 4

Does the second function really not occur when dragging? Do you remove it, or is it running at the same time? I think your enter_frame function and your mouse_move function are fighting each other. in your drag function add this:

stage.removeEventListener(Event.ENTER_FRAME, fl_frameEvent);

and in your drop function add this:

stage.addEventListener(Event.ENTER_FRAME, fl_frameEvent);

Another workaround, I noticed if you zoom way way in on the slider, if you come 99.9% of the way left, but don't quite line it up, it works as expected, so you could just adjust your draggable rectangle to leave just a tiny space on the left side.

SearchBar.x + 4
清浅ˋ旧时光 2024-10-28 17:52:27

我实际上解决了我自己的问题,这就是解决方案。

stage.addEventListener(MouseEvent.MOUSE_MOVE, fl_Drag);

function fl_Drag(event:MouseEvent):void
{
    if(isDraging == true) {
        if(SearchBarSlider.x - (SearchBar.x + 3) < 1){
        } else if(SearchBarSlider.x - (SearchBar.x + 3) < 20){
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3)) / 20) * 320));
        } else if(SearchBarSlider.x - SearchBar.x + 3 >= 20 && SearchBarSlider.x - SearchBar.x + 3 < 40){
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 20) / 20) * 365) + 365);
        } else {
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 40) / 20) * 465) + 685);
        }
    }
}

问题是,当 gotoAndStop 事件在第 1 帧发生时,整个程序重新启动,因为在第 1 帧,动作层重新启动代码。于是,忙碌的拖累就结束了。使用新代码段,搜索栏将不会执行 gotoAndStop(1);

I actually fixed my own problem here's the solution.

stage.addEventListener(MouseEvent.MOUSE_MOVE, fl_Drag);

function fl_Drag(event:MouseEvent):void
{
    if(isDraging == true) {
        if(SearchBarSlider.x - (SearchBar.x + 3) < 1){
        } else if(SearchBarSlider.x - (SearchBar.x + 3) < 20){
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3)) / 20) * 320));
        } else if(SearchBarSlider.x - SearchBar.x + 3 >= 20 && SearchBarSlider.x - SearchBar.x + 3 < 40){
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 20) / 20) * 365) + 365);
        } else {
            gotoAndStop(Math.round(((SearchBarSlider.x - (SearchBar.x + 3) - 40) / 20) * 465) + 685);
        }
    }
}

The problem was that when the gotoAndStop event accured at frame 1 the whole program restarted because at frame 1 the actions layer reinitiates the code. So the drag that was busy got ended. With the new piece of code the searchbar won't execute gotoAndStop(1);

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