我认为我在逻辑某处发现了一个错误但找不到它,我有一个影片剪辑,其中包含4个动画影片剪辑,每个影片都有特定帧的stop()动作,2个按钮,1个移动左边和另一个向右移动,如果用户第一次点击右,右,右,左,左,左,左边的动画,动画按预期工作,但事情就会停止正确评估。
我在变量上使用switch case语句来挑选mc来制作动画,我会更好地使用If Else语句吗?继承我的代码,可能显而易见的动作不是我的强项!
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;
import fl.text.TLFTextField;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
// Global variables
var mcWidth:int = 768;
var mcPosInc:int = 0;
var boxAnimPlay:int = 1;
var mcMoving:Boolean = false;
var buttonClicked:String = "right";
var mcLeft;
var mcRight;
addEventListener(Event.ENTER_FRAME, frameHandler);
// frame Handler
function frameHandler(event:Event):void
{
// Initialize button click events
controlGrp.bttn_left.addEventListener(MouseEvent.CLICK, goLeft);
controlGrp.bttn_right.addEventListener(MouseEvent.CLICK, goRight);
function goLeft(e:MouseEvent):void {
buttonClicked = "left";
// change position
if (mcPosInc > 0 && mcMoving == false) {
mcMoving = true;
mcPosInc --;
boxAnimPlay --;
// Scroll mc1
mcLeft = new Tween(mc1, "x", Regular.easeOut, mc1.x, mc1.x + mcWidth, 1.5, true);
mcLeft.addEventListener(TweenEvent.MOTION_FINISH, end);
function end(event:TweenEvent) {
mcMoving = false;
}
if (boxAnimPlay >= 1) {
switch (boxAnimPlay) {
case 3:
mc1.box4.gotoAndPlay(17);
mc1.box3.gotoAndPlay(31);
break;
case 2:
mc1.box2.gotoAndPlay(31);
mc1.box3.gotoAndPlay(46);
break;
case 1:
mc1.box1.gotoAndPlay(17);
mc1.box2.gotoAndPlay(46);
break;
}
}
trace(boxAnimPlay);
trace(buttonClicked);
}
}
}
// Play movie tests
function goRight(e:MouseEvent):void {
buttonClicked = "right";
// change position
if (mcPosInc < 3 && mcMoving == false) {
mcMoving = true;
mcPosInc ++;
boxAnimPlay ++;
// Scroll mc1
mcRight = new Tween(mc1, "x", Regular.easeOut, mc1.x, mc1.x - mcWidth, 1.5, true);
mcRight.addEventListener(TweenEvent.MOTION_FINISH, end);
function end(event:TweenEvent) {
mcMoving = false;
}
if (boxAnimPlay <= 4) {
switch (boxAnimPlay) {
case 1:
break;
case 2:
mc1.box1.gotoAndPlay(1);
mc1.box2.gotoAndPlay(1);
break;
case 3:
mc1.box2.gotoAndPlay(16);
mc1.box3.gotoAndPlay(1);
break;
case 4:
mc1.box3.gotoAndPlay(16);
mc1.box4.gotoAndPlay(1);
break;
}
}
trace(boxAnimPlay);
trace(buttonClicked);
}
// Add Text Labels to TitleGroup
switch (boxAnimPlay) {
case 1:
readout.text = "test";
break;
}
}
答案 0 :(得分:0)
我修复了它,基本上我在gotoAndPlay中定位的帧包含stop()语句,一旦我定位后续帧,即
而不是:
switch (boxAnimPlay) {
case 3:
mc1.box4.gotoAndPlay(17);
mc1.box3.gotoAndPlay(31);
break;
case 2:
mc1.box2.gotoAndPlay(31);
mc1.box3.gotoAndPlay(46);
break;
case 1:
mc1.box1.gotoAndPlay(17);
mc1.box2.gotoAndPlay(46);
break;
}
我用过这个:
switch (boxAnimPlay) {
case 3:
mc1.box4.gotoAndPlay(17);
mc1.box3.gotoAndPlay(32); // no stop on subsequent frame
break;
case 2:
mc1.box2.gotoAndPlay(32); // no stop on subsequent frame
mc1.box3.gotoAndPlay(47); // no stop on subsequent frame
break;
case 1:
mc1.box1.gotoAndPlay(17);
mc1.box2.gotoAndPlay(47); // no stop on subsequent frame
break;
}