0

我为正在制作的游戏编写了此代码,我只是在学习,没有编译器错误,但是当我运行代码时它失败且没有错误。我有一行我想转到指定的帧,所以代码是 Button_Object.gotoAndStop(Local_Frame) 但它看起来好像程序只是跳过它。我试图把 _root.gotoAndstop(Local_Frame) 和 stage.gotoAndStop(Local_Frame) 但这些都给编译器错误它给出的错误是

 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);
    }

  }

   }
4

1 回答 1

0

AS3 不支持 _root。

尝试

MovieClip(root).gotoAndStop(local_Frame);

PS。代码的一个常见命名约定是使用小驼峰命名法(即以小写字母开头)命名变量,并使用大驼峰命名法命名类(即以大写字母开头)。

This will make your code easier to read and allow you to instantly see which items are variables and classes.

于 2013-02-10T08:03:06.773 回答