3 Replies Latest reply: May 28, 2011 7:38 AM by LukeElChul RSS

    Syntax error: package is unexpected. HELP!.........

    LukeElChul Community Member

      ive got this saving script but every time i press Ctrl + Enter to load the swf

       

      i get an error saying "Scene 1, Layer 'Actions', Frame 1, Line 4 1083: Syntax error: package is unexpected."

       

       

       

      package
      {
      import flash.display.MovieClip;
      import flash.display.SimpleButton;
      import flash.events.MouseEvent;
      import flash.text.TextField;
      import flash.ui.Mouse;
      import flash.net.SharedObject;

      public class Save
      {
      public var sharedObject:SharedObject;
      public function Save()
      {
      Mouse.show();
      savebtn.addEventListener( MouseEvent.CLICK, onClicksave );
      sharedObject = SharedObject.getLocal( "SmimpVars" );
      }
      public function sethunger( hunger:Number ):void
      {
      hunger.text = hunger.toString();
      sharedObject.data.SavedHunger = hunger;
      }
      public function sethunger( hunger:Number ):void
      {
      hunger.text = hunger.toString();
      sharedObject.data.SavedHunger = hunger;
      sharedObject.flush();
      }
      public function sethunger( hunger:Number ):void
      {
      hunger.text = hunger.toString();
      sharedObject.data.SavedHunger = hunger;
      SavedHunger.text = sharedObject.data.SavedHunger.toString();
      sharedObject.flush();
      }
      public function sethunger( hunger:Number ):void
      {
      sharedObject.clear(); // for demonstrating a bug
      hunger.text = hunger.toString();
      if ( hunger > sharedObject.data.SavedHunger )
      {
      sharedObject.data.SavedHunger = hunger;
      }
      SavedHunger.text = sharedObject.data.SavedHunger.toString();
      sharedObject.flush();
      }

        • 1. Re: Syntax error: package is unexpected. HELP!.........
          kglad MVP

          that code should be in a class file, not attached to a timeline.

          • 2. Re: Syntax error: package is unexpected. HELP!.........
            LukeElChul Community Member

            so what bits of this code would i need to take away to make it placeable in the timeline.

             

            all the rest of my codes in the timeline and i havent got a clue how to use packages.

            • 3. Re: Syntax error: package is unexpected. HELP!.........
              kglad MVP

              :

               


              import flash.display.MovieClip;
              import flash.display.SimpleButton;
              import flash.events.MouseEvent;
              import flash.text.TextField;
              import flash.ui.Mouse;
              import flash.net.SharedObject;


              var sharedObject:SharedObject;
              function Save()
              {
              Mouse.show();
              savebtn.addEventListener( MouseEvent.CLICK, onClicksave );
              sharedObject = SharedObject.getLocal( "SmimpVars" );
              }
              function sethunger( hunger:Number ):void
              {
              hunger.text = hunger.toString();
              sharedObject.data.SavedHunger = hunger;
              }
              function sethunger( hunger:Number ):void
              {
              hunger.text = hunger.toString();
              sharedObject.data.SavedHunger = hunger;
              sharedObject.flush();
              }
              function sethunger( hunger:Number ):void
              {
              hunger.text = hunger.toString();
              sharedObject.data.SavedHunger = hunger;
              SavedHunger.text = sharedObject.data.SavedHunger.toString();
              sharedObject.flush();
              }
              function sethunger( hunger:Number ):void
              {
              sharedObject.clear(); // for demonstrating a bug
              hunger.text = hunger.toString();
              if ( hunger > sharedObject.data.SavedHunger )
              {
              sharedObject.data.SavedHunger = hunger;
              }
              SavedHunger.text = sharedObject.data.SavedHunger.toString();
              sharedObject.flush();
              }