Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Replay problem

New Here ,
Dec 30, 2012 Dec 30, 2012

When i play normally, i didnt encounter any problem...but when i pause and replay the animation, it show Cannot access a property or method of a null object reference.
at line as:80. What is the reason ?how can i solve it?

package

{

          import flash.display.MovieClip;

          import flash.events.KeyboardEvent;

          import flash.ui.Keyboard;

          import flash.events.Event;

          import flash.events.MouseEvent;

          import flash.ui.Mouse;

          import flash.utils.Timer;

          import flash.events.TimerEvent;

 

 

          public class Assignment extends MovieClip

          {

                    var vx:int;

                    var vy:int;

                    var collisionHasOccurred:Boolean;

                    var score:uint;

 

                    public function Assignment()

                    {

                              init();

 

                    }

                    function init():void

                    {

                              //Initialize variable

                              vx=0;

                              vy=0;

                              collisionHasOccurred=false;

                              stone.stop();

                              score=0;

                              optionPage.visible=false;

 

                    //Add event listeners

                    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

                    stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

                    addEventListener(Event.ENTER_FRAME, onEnterFrame);

                    }

 

                    function onKeyDown(event:KeyboardEvent):void

                    {

                              if(event.keyCode==Keyboard.LEFT)

                              {

                                        vx=-5;

                              }

                              else if (event.keyCode==Keyboard.RIGHT)

                              {

                                        vx=5;

                              }

                              else if (event.keyCode==Keyboard.UP)

                              {

                                        vy=-5;

 

                              }

                              else if (event.keyCode==Keyboard.DOWN)

                              {

                                        vy=5;

                              }

 

                    }

                    function onKeyUp(event:KeyboardEvent):void

                    {

                              if (event.keyCode==Keyboard.LEFT || event.keyCode==Keyboard.RIGHT)

                              {

                                        vx=0;

                              }

                              else if (event.keyCode==Keyboard.DOWN || event.keyCode==Keyboard.UP)

                              {

                              vy=0;

                              }

                    }

                    function onEnterFrame(event:Event):void

                    {

                              //Move the player

                              player.x+=vx;

                              player.y+=vy;

 

                              //collision detection

                              if (stone.hitTestObject(player))<-----here is line 80

                    {

                              player.gotoAndStop(3);

                              health.meter.width-=2;

                              if (! collisionHasOccurred)

                              {

                                        score++;

                                        messageDisplay.text=String(score);

                                        collisionHasOccurred=true;

                              }

          }

                    else

                    {

                              player.gotoAndStop(1);

                              collisionHasOccurred=false;

                    }

 

                    if (health.meter.width <=1)

                    {

                              New.text="Game Over!";

                              stop();

                              fl_CountDownTimerInstance_3.stop();

 

                    }

                    if (player.hitTestObject(wall))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

                    if (player.hitTestObject(wallA))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

                    if (player.hitTestObject(wallB))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

                    if (player.hitTestObject(wallC))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

                    if (player.hitTestObject(wallD))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

                    if (player.hitTestObject(wallE))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

                    if (player.hitTestObject(wallF))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

                    if (player.hitTestObject(wallG))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

                    if (player.hitTestObject(wallH))

                    {

                              player.x-=vx;

                              player.y-=vy;

                    }

 

 

                              }

          }

}

TOPICS
ActionScript
871
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 30, 2012 Dec 30, 2012

What are you doing when you pause?  Likewise, what are you doing when you replay?

Before line 80 insert the line:  trace(stone); and see if it comes up null after you pause/replay.

Translate
LEGEND ,
Dec 30, 2012 Dec 30, 2012

Which line is line 80?  What is the complete error message?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 30, 2012 Dec 30, 2012

if (stone.hitTestObject(player))<-----here is line 80                    

{                              

player.gotoAndStop(3);                              

health.meter.width-=2;                              

if (! collisionHasOccurred)                             

{                                       

score++;                                      

messageDisplay.text=String(score);            

collisionHasOccurred=true;        

}

                      }

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at Assignment/onEnterFrame()


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 30, 2012 Dec 30, 2012

What are you doing when you pause?  Likewise, what are you doing when you replay?

Before line 80 insert the line:  trace(stone); and see if it comes up null after you pause/replay.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 31, 2012 Dec 31, 2012

hmm,ya..i successfully correct it..thanks for ur great help,friend.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 31, 2012 Dec 31, 2012
LATEST

You're welcome... sounds like you did all the work to fix it... good going.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines