okay, i have this code on frame 1
addEventListener(Event.ENTER_FRAME, changeframe);
function changeframe(event:Event):void
{
btsakhir.y -= 6;
if (btsakhir.y <= 56)
{
nextFrame();
}
}
but when i test it whenever it goes to the next frame it show an Cannot access a property or method of a null object reference. but if in the frame 2 i add the instance btsakhir its not error. but all i want in the frame 2 is, there is no btsakhir, can someone give me solution for this so there is no error when going to frame 2 without btsakhir
What is happening is that when flash goes to the next frame, the Event.ENTER_FRAME event handler is still running. And it expects that there is an object called "btsakhir" with a y property. You can test this by adding a trace in your changeFrame() method and you should see it still tracing, even if it is on the next frame.
Two things you could do:
1.) change your event handler (your changeframe() method) to check and account for when "btsakhir" no longer exists on the next frame. This may get a little messy and not recommended depending on how you choose to do it.
Or
2.) remove the event listener so that it isn't running at all when you go to the next frame. If all the changeframe() method does is check "btsakhir"'s y property, this is would probably a better way to go. To remove the event listener you can add:
this.removeEventListener(Event.ENTER_FRAME, changeframe);
You would add it just before you call nextFrame();
Of course if your object "btsakhir" is supposed to exist on the next frame, (and is an object on the timeline/stage), just add frames to it.