Actionscript 3 gotoAndStop();不会正常工作
我为我制作的一个游戏写了这段代码,我只是在学习,没有编译器错误,但是当我运行代码时,它失败了,没有错误。我有一行代码,我想转到一个指定的帧,因此代码是Button\u Object.gotoAndStop(Local\u frame),但看起来程序只是跳过了它。我已经尝试过放置_root.gotoAndstop(Local_Frame)和stage.gotoAndstop(Local_Frame),但是这两个都会给编译器带来错误,它给出的错误是Actionscript 3 gotoAndStop();不会正常工作,actionscript-3,flash,flash-cs6,Actionscript 3,Flash,Flash Cs6,我为我制作的一个游戏写了这段代码,我只是在学习,没有编译器错误,但是当我运行代码时,它失败了,没有错误。我有一行代码,我想转到一个指定的帧,因此代码是Button\u Object.gotoAndStop(Local\u frame),但看起来程序只是跳过了它。我已经尝试过放置_root.gotoAndstop(Local_Frame)和stage.gotoAndstop(Local_Frame),但是这两个都会给编译器带来错误,它给出的错误是 C:\Users\Nathan\Desktop\
C:\Users\Nathan\Desktop\Matching Game\ClickSolver.as,
Line 34 1120: Access of undefined property _root.
我确实看到了跟踪语句。作为旁注,我试图访问主时间线,而不是对象时间线
这是密码
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class ClickSolver {
private var Button_Object:MovieClip;
private var Check_Object:MovieClip;
private var Score:Number = 0;
private var Local_Frame:Number = 0;
private var Local_Timer:Timer = new Timer(1000,3);
public function ClickSolver(ButtonObject:MovieClip, CheckObject:MovieClip, Frame:Number) {
Local_Frame = Frame;
Button_Object = ButtonObject;
Check_Object = CheckObject;
Button_Object.buttonMode = true;
trace(Button_Object.name);
trace(Check_Object.name);
Local_Timer.start();
trace(Local_Timer.currentCount);
Button_Object.addEventListener(MouseEvent.CLICK, Object_Button_Clicked);
Button_Object.addEventListener(MouseEvent.MOUSE_OVER,Button_Mouse_Over);
Button_Object.addEventListener(MouseEvent.MOUSE_OUT, Button_Mouse_Out);
Local_Timer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerIsDone);
}
private function TimerIsDone (event:TimerEvent):void{
trace("Timer is done");
Local_Timer.stop();
Local_Timer.reset();
Button_Object.gotoAndStop(Local_Frame);
}
private function Button_Mouse_Out (event:MouseEvent):void{
Button_Object.alpha = 1;
}
private function Button_Mouse_Over (event:MouseEvent):void{
Button_Object.alpha = 0.75;
}
private function Object_Button_Clicked (event:MouseEvent):void{
Score++;
Check_Object.visible = false;
Button_Object.gotoAndStop(Local_Frame);
trace("Score: " + Score);
trace("Frame: " + Local_Frame);
}
}
}
_AS3中不支持root 试一试 注:代码的常见命名约定是使用小写字母(即以小写字母开头)命名变量,使用大写字母(即以大写字母开头)命名类
这将使您的代码更易于阅读,并允许您立即查看哪些项是变量和类。我尝试了上面的一行,但出现了错误:
C:\Users\Nathan\Desktop\Matching Game\ClickSolver.as,第36 1120行:访问未定义的属性根代码>好,这里可能有点混乱。您是要转到按钮对象上的帧还是主时间轴上的帧?如果是您的按钮对象,请确保已将您的按钮对象添加到该阶段,例如addChild(buttonObject);我正在尝试访问主时间线您是否文档类扩展MovieClip?i、 我不确定如何通过stackoverflow将.fla发送给你。所以我就把它放在我的网站上。
MovieClip(root).gotoAndStop(local_Frame);