getting error TypeError: Error #1009: Cannot access a property or method of a null object reference
getting error TypeError: Error #1009: Cannot access a property or method of a null object reference
I'm trying to call a function on two buttons
nav1or2.navi1.navBtn1.addEventListener(MouseEvent.CLICK, goSmall);
nav4.navi4.navBtn4.addEventListener(MouseEvent.CLICK, goSmall);
function goSmall(event:MouseEvent):void
{
gotoAndPlay(41);
}
the second button nav4.navi4.navBtn4.addEventListener(MouseEvent.CLICK, goSmall);
is not working and i m getting this TypeError:
nav4.navi4.navBtn4.addEventListener(MouseEvent.CLICK, goSmall);
Error #1009: Cannot access a property or method of a null object
reference.
please help.
nav4.navi4.navBtn4
this is the code only, of if need i can share my file
– Vipul
Aug 10 '13 at 6:09
Yes if you want.
– putvande
Aug 10 '13 at 8:36
3 Answers
3
I resolved it, instead of using this nav1or2.navi1.navBtn1
, nav4.navi4.navBtn4
now I am using nav1or2.navi1
, nav4.navi4
its is working in my case, navBtn4 doesn't have the "addEventListener" but I am not sure why it is not working with this nav4.navi4.navBtn4
if any one know please let me know the url of my file has been changed : http://sdrv.ms/1bo86qQ
nav1or2.navi1.navBtn1
nav4.navi4.navBtn4
nav1or2.navi1
nav4.navi4
nav4.navi4.navBtn4
That means that navBtn4 doesn't have the "addEventListener" method at the time when you're running that code. Try using the debugger with a break point on that line and checking that whether or not it has been initialised.
navBtn4 nad navBtn1 are same location, I am sharing my file here, can you please check skydrive.live.com/… click on division button its working here but its not working with others
– Vipul
Aug 12 '13 at 6:54
url of my file has been changed : sdrv.ms/1bo86qQ
– Vipul
Aug 12 '13 at 7:39
I Found your problem!!!
Fix the code as follows:
nav1or2.navi1.navBtn1.addEventListener(MouseEvent.CLICK, goSmall);
nav4.navi4.navBtn1.addEventListener(MouseEvent.CLICK, goSmall);
function goSmall(event:MouseEvent):void
{
gotoAndPlay(41);
}
Your problem is:
navi1
navi2
navi4
etc...
ARE ALL THE SAME OBJECT!!
When you change one of them you change them all!
So They all contains "navBtn1" and NOT "navBtn4"
Thats why you get Error #1009 because the property "navBtn4" really doesn't exists!!
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you show some more of your code? Is
nav4.navi4.navBtn4
on the displaylist when you try to add the listener?– putvande
Aug 9 '13 at 13:57