Copy link to clipboard
Copied
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at KKK25_fla::MainTimeline/qwe()[KKK25_fla.MainTimeline::frame4:50]
Copy link to clipboard
Copied
on line 50 of frame 4 of your main swf you're trying to reference (with actionscript) an object that doesn't exist (when your code executes).
Copy link to clipboard
Copied
whats the best thing i would do?
here's the code
function qwe(e:Event){
mcGdeJesus.y += 25 / stage.frameRate;
mcMDizon.y += 28 / stage.frameRate;
mcMAquino.y += 30 / stage.frameRate;
mcTMagbanua.y += 42 / stage.frameRate;
mcTTecson.y += 34 / stage.frameRate;
mcJRizal.y += 36 / stage.frameRate;
if(mcGdeJesus.y > stage.stageHeight + mcGdeJesus.height){
mcGdeJesus.x = Math.random() * 450 + 450;
mcGdeJesus.y = -mcGdeJesus.height
}
if(mcMDizon.y > stage.stageHeight + mcGdeJesus.height){
mcMDizon.x = Math.random() * 450 + 450;
mcMDizon.y = -mcMDizon.height
}
if(mcMAquino.y > stage.stageHeight + mcGdeJesus.height){
mcMAquino.x = Math.random() * 450 + 450;
mcMAquino.y = -mcMAquino.height
}
if(mcTMagbanua.y > stage.stageHeight + mcGdeJesus.height){
mcTMagbanua.x = Math.random() * 450 + 450;
mcTMagbanua.y = -mcTMagbanua.height
}
if(mcTTecson.y > stage.stageHeight + mcGdeJesus.height){
mcTTecson.x = Math.random() * 450 + 450;
mcTTecson.y = -mcTTecson.height
}
if(mcJRizal.y > stage.stageHeight + mcGdeJesus.height){
mcJRizal.x = Math.random() * 450 + 450;
mcJRizal.y = -mcJRizal.height
}
}
and when i click the button play, it goes error and here's the code for the button.
mcPlay.addEventListener(MouseEvent.CLICK, GameWOFMenu);
function GameWOFMenu(m:MouseEvent)
{
gotoAndStop(1, "GameMenu");
}
Copy link to clipboard
Copied
which is line 50 of frame 4?
Copy link to clipboard
Copied
after function qwe(e:Event){
line 50 is mcGdeJesus.y += 25 / stage.frameRate;
Copy link to clipboard
Copied
then mcGdeJesus doesn't exist when you see that error message. ie, when you change scenes you go to another keyframe where you probably think mcGdeJesus exists, but it's not the same mcGdeJesus that existed before you changed scenes. and flash doesn't know how to handle two different objects with the same reference.
the easiest remedy is don't use scenes.
if you don't do that, you'll need to assign that 2nd mcGdeJesus a different instance name and use that name at line 50 (eg, use a variable to store the mc's reference), or create a new function to reference that new object in GameMenu.
Copy link to clipboard
Copied
i used scenes to organize my animations.
but i dont need the mcGdeJesus etc. in the next scenes.
Copy link to clipboard
Copied
then don't execute line 50 when you change scenes.
you can always use an if-statement (though that might not be the cleverest way to handle the problem);
if(this.currentScene.name!='GameMenu'){
mcGdeJesus.y += 25 / stage.frameRate;
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now