4 Replies Latest reply on Nov 3, 2011 11:49 PM by McbainGames11

    Error When Using Class :(

    McbainGames11 Level 2

      Hey,

       

      Class:

       

      package

      {

       

          import flash.display.MovieClip;

       

          import flash.events.Event;

       

          public class Main extends MovieClip

          {

       

              public var enemyA:Array = [];

       

              public var birdA:Array = [];

             

              public var rowNum:int = 2;

       

              private var gap:int = 100;

       

              private var obj_no = 2;

             

              public var enemy1:mychar = new mychar();

             

              public var TheBird:BirdChar = new BirdChar();

       

              public function Main()

              {

                  // constructor code

                  createEnemyF();

                 

                  createBirdF();

                 

                  this.addEventListener(Event.ENTER_FRAME,loopF);

       

              }

              public function createEnemyF()

              {

                  for (var i:int = 0; i < rowNum; i++)

                  {

                      for (var j:int = 0; j < obj_no; j++)

                      {

       

                          enemy1.x = Math.random() * stage.stageWidth - enemy1.width;

       

                          enemy1.y = - i * (gap + enemy1.height) - 30.65;

       

                          enemyA.push(enemy1);

       

                          addChild(enemy1);

       

                      }

                  }

              }

              public function createBirdF() {

                 

                  TheBird.x = 270.95;

                 

                  TheBird.y = 350.95;

                 

                  birdA.push(TheBird);

                 

                  addChild(TheBird);

                 

              }

              public function loopF(event:Event) {

                 

                  updateEnemyPositionsF();

                 

                  updateBirdPositionsF();

                 

                  hitTestF();

                 

              }

              public function updateEnemyPositionsF() {

                 

                  enemy1.y +=  2;

                 

              }

              public function updateBirdPositionsF() {

                 

                  TheBird.x = mouseX;

                 

              }

              public function hitTestF() {

                 

                  if(TheBird.hitTestObject(enemy1))

                  {

                     

                      gotoAndPlay(5);

                     

                      trace('The Bird Hit Enemy 1');

                     

                  }

                 

              }

       

          }

       

      }

       

       

      This conflicts and causes this error:

       

      1046: Type was not found or was not a compile-time constant: MouseEvent

       

      ^ ^ Code repeats to all of my event listeners

       

       

      Thanks for your time.

        • 1. Re: Error When Using Class :(
          markerline Level 4

          Looks like you imported events.Event but not events.MouseEvent (or some similar syntax) basically you must import MouseEvents separately from other Events.

          • 2. Re: Error When Using Class :(
            McbainGames11 Level 2

            Thanks, i thought it might be this because of previous problems but i seen i already had : import flash.events.Event; so i thought that would be OK!

             

             

            Second Error:

             

            1180: Call to an undefined method Timer.

             

            I think this is the same sort of thing but what to import to fix this?

             

            So far these are my imports:

             

                import flash.display.MovieClip;

             

                import flash.events.Event;

                 

                import flash.events.MouseEvent;

                 

                import flash.events.TimerEvent;

             

            Thanks for helping.

             

            Date: Thu, 3 Nov 2011 05:36:22 -0600

            From: forums@adobe.com

            To: mcbain97@hotmail.com

            Subject: Error When Using Class

             

             

             

             

             

             

                  

                       

                       

                       

                Re: Error When Using Class

             

             

                created by markerline in Flash Pro - General - View the full discussion

             

             

             

            Looks like you imported events.Event but not events.MouseEvent (or some similar syntax) basically you must import MouseEvents separately from other Events.

             

             

                 Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4005227#4005227

                 To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4005227#4005227. In the Actions box on the right, click the Stop Email Notifications link.

                  

                 Start a new discussion in Flash Pro - General by email or at Adobe Forums

              For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

            1 person found this helpful
            • 3. Re: Error When Using Class :(
              Peter Celuch Level 4

              I don't see any use of "Timer" in code you provided.If you use Timer, you should import it as well.

               

              import flash.utils.Timer;
              

               

              And when calling Timer(), add keyword new before it..

               

              var timer:Timer = new Timer();
              
              1 person found this helpful
              • 4. Re: Error When Using Class :(
                McbainGames11 Level 2

                Thanks mate i knew it wasn't in the code given sorry! Was in the frame :P

                 

                Thanks both for helping, question solved!

                 

                Date: Thu, 3 Nov 2011 16:21:45 -0600

                From: forums@adobe.com

                To: mcbain97@hotmail.com

                Subject: Error When Using Class

                 

                 

                 

                 

                 

                 

                      

                           

                           

                           

                    Re: Error When Using Class

                 

                 

                    created by Peter Celuch in Flash Pro - General - View the full discussion

                 

                 

                 

                I don't see any use of "Timer" in code you provided.If you use Timer, you should import it as well. import flash.utils.Timer;

                And when calling Timer(), add keyword new before it..  var timer:Timer = new Timer();

                 

                 

                 

                     Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4006686#4006686

                     To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4006686#4006686. In the Actions box on the right, click the Stop Email Notifications link.

                      

                     Start a new discussion in Flash Pro - General by email or at Adobe Forums

                  For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.