我的Flash漫画遇到问题

时间:2017-05-13 19:53:29

标签: actionscript-3

我现在正在Adobe Animate中制作一个webcomic,并且通过点击屏幕,观众可以转动“页面”的方式。

首先,我将代码放在一帧上,如下所示:

import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;

stop();
stage.addEventListener(MouseEvent.CLICK,forward2);
stage.addEventListener (KeyboardEvent.KEY_DOWN,forward);


function forward2 (event:MouseEvent) :void {
gotoAndStop(currentFrame+1);
}

function forward (e:KeyboardEvent): void {
if (e.keyCode == Keyboard.RIGHT)
gotoAndStop(currentFrame+1);
}

然后,如果我想在没有观众不必点击屏幕的情况下播放一个场景,我写了另一个代码:

import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;

stop();
stage.addEventListener(MouseEvent.CLICK,forward4);
stage.addEventListener (KeyboardEvent.KEY_DOWN,forward3);


function forward4 (event:MouseEvent) :void {
gotoAndPlay(currentFrame+1);
}

function forward3 (e:KeyboardEvent): void {
if (e.keyCode == Keyboard.RIGHT)
gotoAndPlay(currentFrame+1);
}

因为该函数已在另一帧上定义,我在动画后将该代码发布在帧上:

import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;

stop();
stage.addEventListener(MouseEvent.CLICK,forward2);
stage.addEventListener (KeyboardEvent.KEY_DOWN,forward);

我试图确保脚本在我希望它用于的整个帧中是恒定的,方法是为每个帧我插入一个空白帧,我希望它是活动的。然而,当我测试它时,一旦我点击框架我就把代码打开(没有定义函数的那个​​),它只是把我送回了开头。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

向任何对象添加侦听器时,它将继续存在,直到明确删除它为止。

进入下一帧之前,您应该运行:

10

这将删除事件侦听器,并在您单击或按某个其他帧上的某个键时阻止stage.removeEventListener(MouseEvent.CLICK, forward2); stage.removeEventListener(KeyboardEvent.KEY_DOWN, forward); forward2运行。