0

I wrote this code for a game im making, Im just learning, There are no compiler errors but when i run the code it fails with no errors. I have a line where i would like to goto a specified frame so the code is Button_Object.gotoAndStop(Local_Frame) but it looks as if the program just skips over it. I have tried to put _root.gotoAndstop(Local_Frame) and stage.gotoAndStop(Local_Frame) but these both give compiler errors the error it gives is

 C:\Users\Nathan\Desktop\Matching Game\ClickSolver.as, 
 Line 34    1120: Access of undefined property _root. 

I do see the trace statements. As a side note im trying to access the the main time line, not the objects timeline.

here's the code

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

  }

   }
Nathan
  • 23
  • 1
  • 3

1 Answers1

0

_root isn't supported in AS3.

Try

MovieClip(root).gotoAndStop(local_Frame);

PS. A common naming convention for you code is to name variables using lower camelCase (i.e. start with a lowercase letter) and name classes with upper CamelCase (i.e. start with an uppercase letter).

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

crooksy88
  • 3,849
  • 1
  • 24
  • 30
  • I tried the line above but i get the error: `C:\Users\Nathan\Desktop\Matching Game\ClickSolver.as, Line 36 1120: Access of undefined property root. ` – Nathan Feb 10 '13 at 08:17
  • Ok there might be a little confusion here. Are you trying to go to a frame on your button object or on the main timeline? If it's your button object, make sure your button object has been added to the stage, e.g. addChild(buttonObject); – crooksy88 Feb 10 '13 at 10:32
  • I'm trying to access the main time line – Nathan Feb 10 '13 at 21:36
  • Does you document class extend MovieClip? i.e. the first class which builds your file. – crooksy88 Feb 11 '13 at 09:10
  • Im not exactly sure how i could send you the .fla through stackoverflow. so i just hosted it on my website. http://nate066.weebly.com/uploads/6/6/0/1/6601389/matching_game.zip – Nathan Feb 12 '13 at 01:17
  • There are a couple of fundamental issues with how you are setting up your files. Have a look at what I've done and see if it makes sense. The particular problem you were having is that ClickSolver was not being added to the stage 'addChild()' so it didn't have access to the timeline. http://www.infin8design.com/clients/stack/matching_game.zip – crooksy88 Feb 12 '13 at 07:33
  • You added a main class and then link and flash add it into the project by adding it to source in actionscript 3 setting. Then you had the main class just link to the clicksolver class. Is that right? – Nathan Feb 12 '13 at 20:32
  • Sorry Nathan I don't understand what you're asking. – crooksy88 Feb 14 '13 at 07:18
  • Thanks for fixing the problem I thought only GUI elements had to be added to the stage. Oh we'll my bad – Nathan Feb 14 '13 at 18:35