简体   繁体   English

Flash CC-HTML5 Canvas:幻灯片导航

[英]Flash CC - HTML5 Canvas: Slideshow Navigation

I am trying to create a simple 3 image slideshow with a next and back button in Flash CC using HTML5 Canvas. 我正在尝试使用HTML5 Canvas在Flash CC中创建一个带有下一个和后退按钮的简单3图像幻灯片。 I'm new to javascript and seem to be having an issue with it working. 我是javascript新手,似乎无法正常工作。

this.stop();

this.next_btn.addEventListener("click", playClickNext.bind(this));

function playClickNext() 
{
    this.gotoAndStop(this.currentFrame + 1);
}


this.back_btn.addEventListener("click", playClickBack.bind(this));

function playClickBack() 
{
    this.gotoAndStop(this.currentFrame - 1);
}

I'm getting it to publish and the next button works but sometimes goes to the wrong frame. 我正在发布它,并且下一个按钮可以使用,但是有时转到错误的框架。 The back button sometimes work and sometimes doesn't. 后退按钮有时有效,有时却无效。 The most common thing it does is also go back to a random frame when clicked. 最常见的做法是单击时返回随机帧。

Thanks for any help! 谢谢你的帮助!

I put together a quick sample, and got a similar result. 我整理了一个快速样本,得到了类似的结果。 The issue for me was that the frame that the script was on would fire any time you went to that frame. 对我来说,问题在于脚本所在的框架会在您转到该框架时触发。 This meant that the listeners on the button would pile up, and fire multiple times. 这意味着按钮上的听众会堆积,并触发多次。

The ideal solution is to pull the code out of the FLA, and into your HTML/JS app. 理想的解决方案是将代码从FLA中拉出,并进入HTML / JS应用程序。 You can target the timeline directly using the instance names. 您可以使用实例名称直接定位时间轴。 For example, in my app, it is all on the main timeline, so you can use: 例如,在我的应用程序中,它们全部位于主时间轴上,因此您可以使用:

exportRoot.next_btn.addEventListener("click", handler);

To solve it without rearchitecting, you could also just ensure that either: 要解决此问题而不进行重新整理,您还可以确保:

  1. Your frame with the script is never navigated to. 带有脚本的框架永远不会导航到。 You could make your "first" frame 2 frames long, and put the code on frame 1, and the stop() on frame 2. Then just ensure you never gotoAndStop on 1. You will have to put restrictions on both previous and next, because you can gotoAndStop at a higher frame than the max, and it will wrap. 您可以将“第一”帧加长2帧,然后将代码放在第1帧,将stop()放在第2帧。然后确保您永远不要将gotoAndStop放在1上。您必须在上一个和下一个上都设置限制,因为您可以将gotoAndStop置于比最大帧高的帧上,并且它将自动换行。
  2. Remove all the event listeners each frame. 每帧删除所有事件侦听器。 The way you set up your listeners using bind is problematic for removal, so I recommend just removing all listeners. 使用bind设置侦听器的方式对于删除是有问题的,因此我建议仅删除所有侦听器。

I uploaded a quick sample here [ https://dl.dropboxusercontent.com/u/2224806/Nav.fla ] that uses the second approach, mainly because it is an easy fix. 我在此处[ https://dl.dropboxusercontent.com/u/2224806/Nav.fla ]上传了一个使用第二种方法的快速示例,主要是因为它很容易解决。 Sorry, link expired 抱歉,链接已过期

Let me know if this solves your issue, or if it is related to something else. 让我知道这是否解决了您的问题,或者是否与其他问题有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM