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

Loop for a game.

New Here ,
Mar 22, 2017 Mar 22, 2017

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.

TOPICS
ActionScript
309
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

Community Expert , Mar 23, 2017 Mar 23, 2017

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

use the trace function to find which and confirm.

Translate
Community Expert ,
Mar 22, 2017 Mar 22, 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.

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 ,
Mar 23, 2017 Mar 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...

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
Community Expert ,
Mar 23, 2017 Mar 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.

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 ,
Mar 23, 2017 Mar 23, 2017

I still dont get it.

Indeed, if i do:

addEventListener(Event.ENTER_FRAME, doStuffConstantly);

function doStuffConstantly(evt:Event):void

{

  if(hit)

{

  if (branche.hitTestObject(gobranche))

  {

  trace(5);

  }

}

}

The code works perfectly so I suppose that branche and gobranche do exist. But when I use gotoandplay() there is the error 1009 and I dont understand why.

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
Community Expert ,
Mar 23, 2017 Mar 23, 2017

if that's true, there's probably code on frame 4 causing the error.

but again click file>publish settings>tick 'permit debugging' so you can see the line number with the error so making inferences about what's causing the error is unneeded.

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 ,
Mar 23, 2017 Mar 23, 2017

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

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
Community Expert ,
Mar 23, 2017 Mar 23, 2017
LATEST

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

use the trace function to find which and confirm.

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