Copy link to clipboard
Copied
I'm starting a game on this platform I saw a video where it was that code and never gave faults but to me if when I I to chop the main button appears to me:
TypeError: Error # 1009: Cannot access a property or method of a null object reference.
At main/ElegirNivel () [Main:: frame: 7]
This is the code of the button:
Import Flash. MouseEvent;
Stop ();
Boton100. Addeventlistener() (mouseevent. click, ElegirNivel);
function ElegirNivel (e:MouseEvent) {
MovieClip (Root). gotoAndStop (1, "SeleccionNiveles");
Boton100. RemoveEventListener (mouseevent. click, ElegirNivel);
}
And that code redirects the second that I put it in case that is the problem:
Stop ();
Addeventlistener() (mouseevent. click, select);
function Selection (e:MouseEvent) {
if (e. Target == NIVEL1) {
RemoveEventListener (mouseevent. click, select);
MovieClip (Root). gotoAndStop (1, "Nivel1");
}
}
I'm starting on this so your help would make it easier for me to understand.
Thanks for helping me out.
Copy link to clipboard
Copied
The error is pointing at frame 1, line 7 of the Main timeline. Whatever object your code is trying to target at that point in time does not exist.
The 1009 error indicates that one of the objects being targeted by your code is out of scope. This could mean that the object....
- is declared but not instantiated
- doesn't have an instance name (or the instance name is mispelled)
- does not exist in the frame where that code is trying to talk to it
- is animated into place but is not assigned instance names in every keyframe for it
- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).
Also, if that code you show is in the main timeline, there is definitely no need to be using MovieClip (Root)...
One more, if you are just starting out then it is a good time to get away from using scenes. Navigating them can be problematic.
And one more... You should avoid using capital letters for naming things and functions as you appear to be doing. As a common practice, only class names (and event identifiers) start with capital letters... instance names, variables, event listeners, and function names normally start with lower case letters. It helps to follow the common practices because it helps others to more easily interpret your code.
Stop () => stop()
Addeventlistener => addEventListener
Removeeventlistener => removeEventListener
e.Target => e.target
Root => root
mouseevent.click => MouseEvent.CLICK
etc...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now