Skip to main content
Participating Frequently
March 22, 2017
Answered

Loop for a game.

  • March 22, 2017
  • 1 reply
  • 361 views

Hello,

I'm sure that my question has been asked many times but I can't find the proper solution.

I've created a game where the action take place in the frame 2. Everytime that the animation goes to frame 3 I use gotoAndPlay(2) to have an infinite loop. It works but  I think this is not a clean way to do it,. I read about the function sym.play() but I dont know how to use it,

Thanks.

This topic has been closed for replies.
Correct answer kglad

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

  at testbouton_fla::MainTimeline/doStuffConstantly()[testbouton_fla.MainTimeline::frame3:43]

The line 43 is where I have: if (branche.hitTestObject(gobranche)) , In the frame 4 I only have: stop();


then branche or gobranche don't exist when the code executes.

use the trace function to find which and confirm.

1 reply

kglad
Community Expert
Community Expert
March 23, 2017

typically some block of code executes repeatedly (in frame 2) that accounts for the animation.  put that block of code in a function and call that function using a timer or enterframe loop.

AircerAuthor
Participating Frequently
March 23, 2017

Okay but how I do that ? I tried enterframe loop like this:

addEventListener(Event.ENTER_FRAME, doStuffConstantly);

function doStuffConstantly(evt:Event):void

{

  if(hit)

{

  if (branche.hitTestObject(gobranche))

  {

  gotoAndPlay(4);

  }

}

}

but i got error 1009...

kglad
Community Expert
Community Expert
March 23, 2017

if error is because of the code you posted, branche or gobranche don't exist when the code executes.

click file>publish settings>tick 'permit debugging' so you can see the line number with the error.