9 Replies - 8198 Views - Last Post: 01 March 2011 - 06:39 PM

#1 kelly_b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-February 11

Error #1009: Cannot access a property or method of a null object refer

Posted 17 February 2011 - 01:39 PM

Ok I am working on a flash website. I have run into this error: Error #1009: Cannot access a property or method of a null object reference. and I cannot seem to solve this. Here is my set up:

Frame 1
I have code for the bars that serve as starter nav. There are 2 sides to these bars (sidea, sideb). When you roll over the bar, it flips. Sidea is an image, sideb is a movieclip that holds the 'buttons' to go to the content pages.

Frame 2*
This is where I have the code for the content pages.

*This is just code to test that nothing was happening after I went to the next frame

When you click on the buttons on sideb to goes to the appropriate place but it throws this error Error #1009: Cannot access a property or method of a null object reference. I have googled and googled, to no avail.

I can post source file if it helps...

Thanks in advance!!!

Here is the code in frame 1:

stop();

import fl.transitions.Tween;
import fl.transitions.easing.Strong;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;


//REMOVED FLIP FROM PATH TO MAKE ROLLOVER OCCUR WHEN MOUSED OVER BAR
conTop.sidea.addEventListener(MouseEvent.MOUSE_OVER,onflip);
conTop.sideb.addEventListener(MouseEvent.MOUSE_OVER,onflip);
addEventListener(Event.ENTER_FRAME,loop);

conMid.sideaMid.addEventListener(MouseEvent.MOUSE_OVER,onflipMid);
conMid.sidebMid.addEventListener(MouseEvent.MOUSE_OVER,onflipMid);
addEventListener(Event.ENTER_FRAME,loopMid);

conBott.sideaBott.addEventListener(MouseEvent.MOUSE_OVER,onflipBott);
conBott.sidebBott.addEventListener(MouseEvent.MOUSE_OVER,onflipBott);
addEventListener(Event.ENTER_FRAME,loopBott);

var isStill:Boolean=true;
var arraytween:Array = new Array();

function onflip(e:Event) {
 if (isStill) {
  arraytween.push(new Tween(conTop,'rotationX',Strong.easeOut,conTop.rotationX,conTop.rotationX+180,1,true));
  arraytween[0].addEventListener(TweenEvent.MOTION_FINISH,reset);
  conTop.sideb.gotoAndPlay("start");
  isStill=false;
 }
}

function onflipMid(e:Event) {
 if (isStill) {
  arraytween.push(new Tween(conMid,'rotationX',Strong.easeOut,conMid.rotationX,conMid.rotationX+180,1,true));
  arraytween[0].addEventListener(TweenEvent.MOTION_FINISH,resetMid);
  conMid.sidebMid.gotoAndPlay("start");
  isStill=false;
 }
}

function onflipBott(e:Event) {
 if (isStill) {
  arraytween.push(new Tween(conBott,'rotationX',Strong.easeOut,conBott.rotationX,conBott.rotationX+180,1,true));
  arraytween[0].addEventListener(TweenEvent.MOTION_FINISH,resetBott);
  conBott.sidebBott.gotoAndPlay("start");
  isStill=false;
 }
}


function reset(e:Event) {
 isStill=true;
 arraytween=[];
}

function resetMid(e:Event) {
 isStill=true;
 arraytween=[];
}

function resetBott(e:Event) {
 isStill=true;
 arraytween=[];
}


function loop(e:Event) {

 if (conTop.rotationX>=90 && conTop.rotationX<=270) {
  conTop.addChild(conTop.sideb);
  conTop.scaleY=-1; 
 } 
 
 else {
  conTop.addChild(conTop.sidea);
  conTop.scaleY=1;
 }
 
 if (conTop.rotationX>=360) {
  conTop.rotationX=0;
 }

}

function loopMid(e:Event) {

 if (conMid.rotationX>=90 && conMid.rotationX<=270) {
  conMid.addChild(conMid.sidebMid);
  conMid.scaleY=-1; 
 } 
 
 else {
  conMid.addChild(conMid.sideaMid);
  conMid.scaleY=1;
 }
 
 if (conMid.rotationX>=360) {
  conMid.rotationX=0;
 }

}

function loopBott(e:Event) {

 if (conBott.rotationX>=90 && conBott.rotationX<=270) {
  conBott.addChild(conBott.sidebBott);
  conBott.scaleY=-1; 
 } 
 
 else {
  conBott.addChild(conBott.sideaBott);
  conBott.scaleY=1;
 }
 
 if (conBott.rotationX>=360) {
  conBott.rotationX=0;
 }

}

//code to make buttons go to content pages
conTop.sideb.menuBtn.addEventListener(MouseEvent.CLICK,onRollOverHandler);

conTop.sideb.menuBtn.buttonMode = true;
conTop.sideb.menuBtn.useHandCursor = true;

function onRollOverHandler(e:MouseEvent){
	conTop.sideb.gotoAndPlay("fadeOut");
	gotoAndStop("startExtend");
}

conTop.sideb.drinksBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerD);

conTop.sideb.drinksBtn.buttonMode = true;
conTop.sideb.drinksBtn.useHandCursor = true;

function onRollOverHandlerD(e:MouseEvent){
	conTop.sideb.gotoAndPlay("fadeOut");
	gotoAndStop("startExtend");
}

conTop.sideb.specialsBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerS);

conTop.sideb.specialsBtn.buttonMode = true;
conTop.sideb.specialsBtn.useHandCursor = true;

function onRollOverHandlerS(e:MouseEvent){
	conTop.sideb.gotoAndPlay("fadeOut");
	gotoAndStop("startExtend");
}


conMid.sidebMid.caterBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerC);

conMid.sidebMid.caterBtn.buttonMode = true;
conMid.sidebMid.caterBtn.useHandCursor = true;

function onRollOverHandlerC(e:MouseEvent){
	conMid.sidebMid.gotoAndPlay("fadeOutM");
	gotoAndStop("startExtendMid");
}

conMid.sidebMid.aboutBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerA);

conMid.sidebMid.aboutBtn.buttonMode = true;
conMid.sidebMid.aboutBtn.useHandCursor = true;

function onRollOverHandlerA(e:MouseEvent){
	conMid.sidebMid.gotoAndPlay("fadeOutM");
	gotoAndStop("startExtendMid");
}

conBott.sidebBott.lapazBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerL);

conBott.sidebBott.lapazBtn.buttonMode = true;
conBott.sidebBott.lapazBtn.useHandCursor = true;

function onRollOverHandlerL(e:MouseEvent){
	conBott.sidebBott.gotoAndPlay("fadeOutB");
	gotoAndStop("startExtendBott");
}

conBott.sidebBott.contactBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerCo);

conBott.sidebBott.contactBtn.buttonMode = true;
conBott.sidebBott.contactBtn.useHandCursor = true;

function onRollOverHandlerCo(e:MouseEvent){
	conBott.sidebBott.gotoAndPlay("fadeOutB");
	gotoAndStop("startExtendBott");
}



and frame 2

stop();

import fl.transitions.Tween;
import fl.transitions.easing.Strong;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.*;
import flash.net.URLRequest;


boxExTop.nav.menuBtnE.addEventListener(MouseEvent.CLICK, tester)


function tester(e:MouseEvent){
	gotoAndStop("test");
}





Is This A Good Question/Topic? 0
  • +

Replies To: Error #1009: Cannot access a property or method of a null object refer

#2 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 18 February 2011 - 01:54 AM

When the error shows up, it also tells which line or function in your code threw that error.

Run your program, note down the place of error and let us know.
Was This Post Helpful? 0
  • +
  • -

#3 kelly_b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-February 11

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 18 February 2011 - 09:04 AM

It is throwing the error with the loop functions:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at laPaz7_fla::MainTimeline/loop()[laPaz7_fla.MainTimeline::frame1:72]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at laPaz7_fla::MainTimeline/loopMid()[laPaz7_fla.MainTimeline::frame1:90]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at laPaz7_fla::MainTimeline/loopBott()[laPaz7_fla.MainTimeline::frame1:108]



Was This Post Helpful? 0
  • +
  • -

#4 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 18 February 2011 - 09:24 AM

Its most probably because your movie clip conTop is null at some point of execution.
To be sure try this :
function loop(e:Event) {
 trace(conTop); // Should trace null when you get error
 if (conTop.rotationX>=90 && conTop.rotationX<=270) {
  conTop.addChild(conTop.sideb);
  conTop.scaleY=-1; 
 } 
 
 else {
  conTop.addChild(conTop.sidea);
  conTop.scaleY=1;
 }
 
 if (conTop.rotationX>=360) {
  conTop.rotationX=0;
 }

}



To solve it, remove the listeners from the movie clips(conTop,conMid,conBott) before navigating away from their frame.

This post has been edited by chinchang: 18 February 2011 - 09:25 AM

Was This Post Helpful? 0
  • +
  • -

#5 kelly_b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-February 11

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 21 February 2011 - 10:03 AM

Thank you soooo much it worked!!!!! But (isn't there always a 'but') now I am getting a similar error but in another place and I have fiddled with it (which is why it took so long to get back) and I am not sure why. here is the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at laPaz7_fla::MainTimeline/frame2()[laPaz7_fla.MainTimeline::frame2:12]
at flash.display::MovieClip/gotoAndStop()
at laPaz7_fla::MainTimeline/onRollOverHandler()[laPaz7_fla.MainTimeline::frame1:163]

This occurs when I click the buttons in the section commented //code to make buttons go to content pages. I added the removeEventListener to that section of code and it threw the loop function code, then I tried to put it in frame 2, but I get the error listed above. Sigh. Thanks again in advance for your help :)


here is the code for frame 1:

stop();

import fl.transitions.Tween;
import fl.transitions.easing.Strong;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;


//REMOVED FLIP FROM PATH TO MAKE ROLLOVER OCCUR WHEN MOUSED OVER BAR
conTop.sidea.addEventListener(MouseEvent.MOUSE_OVER,onflip);
conTop.sideb.addEventListener(MouseEvent.MOUSE_OVER,onflip);
addEventListener(Event.ENTER_FRAME,loop);

conMid.sideaMid.addEventListener(MouseEvent.MOUSE_OVER,onflipMid);
conMid.sidebMid.addEventListener(MouseEvent.MOUSE_OVER,onflipMid);
addEventListener(Event.ENTER_FRAME,loopMid);

conBott.sideaBott.addEventListener(MouseEvent.MOUSE_OVER,onflipBott);
conBott.sidebBott.addEventListener(MouseEvent.MOUSE_OVER,onflipBott);
addEventListener(Event.ENTER_FRAME,loopBott);

var isStill:Boolean=true;
var arraytween:Array = new Array();

function onflip(e:Event) {
 if (isStill) {
  arraytween.push(new Tween(conTop,'rotationX',Strong.easeOut,conTop.rotationX,conTop.rotationX+180,1,true));
  arraytween[0].addEventListener(TweenEvent.MOTION_FINISH,reset);
  conTop.sideb.gotoAndPlay("start");
  isStill=false;
 }
}

function onflipMid(e:Event) {
 if (isStill) {
  arraytween.push(new Tween(conMid,'rotationX',Strong.easeOut,conMid.rotationX,conMid.rotationX+180,1,true));
  arraytween[0].addEventListener(TweenEvent.MOTION_FINISH,resetMid);
  conMid.sidebMid.gotoAndPlay("start");
  isStill=false;
 }
}

function onflipBott(e:Event) {
 if (isStill) {
  arraytween.push(new Tween(conBott,'rotationX',Strong.easeOut,conBott.rotationX,conBott.rotationX+180,1,true));
  arraytween[0].addEventListener(TweenEvent.MOTION_FINISH,resetBott);
  conBott.sidebBott.gotoAndPlay("start");
  isStill=false;
 }
}


function reset(e:Event) {
 isStill=true;
 arraytween=[];
}

function resetMid(e:Event) {
 isStill=true;
 arraytween=[];
}

function resetBott(e:Event) {
 isStill=true;
 arraytween=[];
}


function loop(e:Event) {
// trace(conTop); // Should trace null when you get error
 if (conTop.rotationX>=90 && conTop.rotationX<=270) {
  conTop.addChild(conTop.sideb);
  conTop.scaleY=-1; 
 } 
 
 else {
  conTop.addChild(conTop.sidea);
  conTop.scaleY=1;
 }
 
 if (conTop.rotationX>=360) {
  conTop.rotationX=0;
  ;

 }

}




//function loop(e:Event) {
//
// if (conTop.rotationX>=90 && conTop.rotationX<=270) {
//  conTop.addChild(conTop.sideb);
//  conTop.scaleY=-1; 
// } 
// 
// else {
//  conTop.addChild(conTop.sidea);
//  conTop.scaleY=1;
// }
// 
// if (conTop.rotationX>=360) {
//  conTop.rotationX=0;
// }

//}

function loopMid(e:Event) {

 if (conMid.rotationX>=90 && conMid.rotationX<=270) {
  conMid.addChild(conMid.sidebMid);
  conMid.scaleY=-1; 
 // this.removeEventListener(Event.ENTER_FRAME,loop);
//  this.removeEventListener(Event.ENTER_FRAME,loopMid);
//  this.removeEventListener(Event.ENTER_FRAME,loopBott); 
 } 
 
 else {
  conMid.addChild(conMid.sideaMid);
  conMid.scaleY=1;
  
 }
 
 if (conMid.rotationX>=360) {
  conMid.rotationX=0;
 }

}

function loopBott(e:Event) {

 if (conBott.rotationX>=90 && conBott.rotationX<=270) {
  conBott.addChild(conBott.sidebBott);
  conBott.scaleY=-1;
 // this.removeEventListener(Event.ENTER_FRAME,loop);
//  this.removeEventListener(Event.ENTER_FRAME,loopMid);
//  this.removeEventListener(Event.ENTER_FRAME,loopBott);
 } 
 
 else {
  conBott.addChild(conBott.sideaBott);
  conBott.scaleY=1;
  
 }
 
 if (conBott.rotationX>=360) {
  conBott.rotationX=0;
 }

}

//code to make buttons go to content pages
conTop.sideb.menuBtn.addEventListener(MouseEvent.CLICK,onRollOverHandler);

conTop.sideb.menuBtn.buttonMode = true;
conTop.sideb.menuBtn.useHandCursor = true;

function onRollOverHandler(e:MouseEvent){
	conTop.sideb.gotoAndPlay("fadeOut");
	gotoAndStop("startExtend");
	  this.removeEventListener(Event.ENTER_FRAME,loop);
  	  this.removeEventListener(Event.ENTER_FRAME,loopMid);
  	  this.removeEventListener(Event.ENTER_FRAME,loopBott);
}

conTop.sideb.drinksBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerD);

conTop.sideb.drinksBtn.buttonMode = true;
conTop.sideb.drinksBtn.useHandCursor = true;

function onRollOverHandlerD(e:MouseEvent){
	conTop.sideb.gotoAndPlay("fadeOut");
	gotoAndStop("startExtend");
	this.removeEventListener(Event.ENTER_FRAME,loop);
  	this.removeEventListener(Event.ENTER_FRAME,loopMid);
  	this.removeEventListener(Event.ENTER_FRAME,loopBott);
}

conTop.sideb.specialsBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerS);

conTop.sideb.specialsBtn.buttonMode = true;
conTop.sideb.specialsBtn.useHandCursor = true;

function onRollOverHandlerS(e:MouseEvent){
	conTop.sideb.gotoAndPlay("fadeOut");
	gotoAndStop("startExtend");
	this.removeEventListener(Event.ENTER_FRAME,loop);
  	this.removeEventListener(Event.ENTER_FRAME,loopMid);
  	this.removeEventListener(Event.ENTER_FRAME,loopBott);
}


conMid.sidebMid.caterBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerC);

conMid.sidebMid.caterBtn.buttonMode = true;
conMid.sidebMid.caterBtn.useHandCursor = true;

function onRollOverHandlerC(e:MouseEvent){
	conMid.sidebMid.gotoAndPlay("fadeOutM");
	gotoAndStop("startExtendMid");
	this.removeEventListener(Event.ENTER_FRAME,loop);
  	this.removeEventListener(Event.ENTER_FRAME,loopMid);
  	this.removeEventListener(Event.ENTER_FRAME,loopBott);
}

conMid.sidebMid.aboutBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerA);

conMid.sidebMid.aboutBtn.buttonMode = true;
conMid.sidebMid.aboutBtn.useHandCursor = true;

function onRollOverHandlerA(e:MouseEvent){
	conMid.sidebMid.gotoAndPlay("fadeOutM");
	gotoAndStop("startExtendMid");
	this.removeEventListener(Event.ENTER_FRAME,loop);
  	this.removeEventListener(Event.ENTER_FRAME,loopMid);
  	this.removeEventListener(Event.ENTER_FRAME,loopBott);
}

conBott.sidebBott.lapazBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerL);

conBott.sidebBott.lapazBtn.buttonMode = true;
conBott.sidebBott.lapazBtn.useHandCursor = true;

function onRollOverHandlerL(e:MouseEvent){
	conBott.sidebBott.gotoAndPlay("fadeOutB");
	gotoAndStop("startExtendBott");
	this.removeEventListener(Event.ENTER_FRAME,loop);
  	this.removeEventListener(Event.ENTER_FRAME,loopMid);
  	this.removeEventListener(Event.ENTER_FRAME,loopBott);
}

conBott.sidebBott.contactBtn.addEventListener(MouseEvent.CLICK,onRollOverHandlerCo);

conBott.sidebBott.contactBtn.buttonMode = true;
conBott.sidebBott.contactBtn.useHandCursor = true;

function onRollOverHandlerCo(e:MouseEvent){
	conBott.sidebBott.gotoAndPlay("fadeOutB");
	gotoAndStop("startExtendBott");
	this.removeEventListener(Event.ENTER_FRAME,loop);
  	this.removeEventListener(Event.ENTER_FRAME,loopMid);
  	this.removeEventListener(Event.ENTER_FRAME,loopBott);
}




and frame 2 code

stop();

import fl.transitions.Tween;
import fl.transitions.easing.Strong;
import fl.transitions.TweenEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.*;
import flash.net.URLRequest;


boxExTop.nav.menuBtnE.addEventListener(MouseEvent.CLICK, tester);

function tester(e:MouseEvent){
trace("I was clicked!");
boxExTop.nav.menuBtnE.removeEventListener(MouseEvent.CLICK, tester);
conTop.sideb.menuBtn.removeEventListener(MouseEvent.CLICK,onRollOverHandler)
}


Was This Post Helpful? 0
  • +
  • -

#6 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 21 February 2011 - 10:25 AM

It would be better if you could attach your fla file here. The code alone won't help much in identifying the errors.
Was This Post Helpful? 0
  • +
  • -

#7 kelly_b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-February 11

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 21 February 2011 - 10:55 AM

i have tried to upload my fla and it tells me I am not permitted to upload this kind of file

ha. nevermind. here it is zipped

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#8 kelly_b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-February 11

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 25 February 2011 - 10:18 AM

any ideas?
Was This Post Helpful? 0
  • +
  • -

#9 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 25 February 2011 - 11:14 AM

I guess you are using Flash CS4/CS5. Save your .fla for CS3 and then upload it.
Was This Post Helpful? 0
  • +
  • -

#10 kelly_b  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-February 11

Re: Error #1009: Cannot access a property or method of a null object refer

Posted 01 March 2011 - 06:39 PM

unfortunately i lose my 3d functionality and that is a huge part of my site.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1