Copy link to clipboard
Copied
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.
then branche or gobranche don't exist when the code executes.
use the trace function to find which and confirm.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
then branche or gobranche don't exist when the code executes.
use the trace function to find which and confirm.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now