我的 Flash 漫画有问题
Having trouble with my Flash Comic
我现在正在用 Adobe Animate 制作网络漫画,观看者可以通过单击屏幕来转动 "page"。
首先我在一帧上放了一段代码如下:
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);
我试图通过为每个我希望它处于活动状态的帧插入一个空白帧来确保脚本在我希望它用于的整个帧中保持不变。然而,当我测试它时,只要我点击框架,我就把代码放在上面(没有定义函数的那个),它只是让我回到开始。
我做错了什么?
当您向任何对象添加侦听器时,它将继续存在,直到被明确删除。
在进入下一帧之前你应该运行:
stage.removeEventListener(MouseEvent.CLICK, forward2);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, forward);
这将删除事件侦听器并防止 forward2
和 forward
在您单击或按下其他帧上的某个键时 运行ning。
我现在正在用 Adobe Animate 制作网络漫画,观看者可以通过单击屏幕来转动 "page"。
首先我在一帧上放了一段代码如下:
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);
我试图通过为每个我希望它处于活动状态的帧插入一个空白帧来确保脚本在我希望它用于的整个帧中保持不变。然而,当我测试它时,只要我点击框架,我就把代码放在上面(没有定义函数的那个),它只是让我回到开始。
我做错了什么?
当您向任何对象添加侦听器时,它将继续存在,直到被明确删除。
在进入下一帧之前你应该运行:
stage.removeEventListener(MouseEvent.CLICK, forward2);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, forward);
这将删除事件侦听器并防止 forward2
和 forward
在您单击或按下其他帧上的某个键时 运行ning。