Skip to main content
Known Participant
September 14, 2011
Answered

Button url links not working

  • September 14, 2011
  • 1 reply
  • 689 views

Hi All

would someone mind taking a look at this code, I have 6 buttons, for some reason only the first button(my_home) works, can anyone see anything wrong?

many thanks for your help

my_home.addEventListener(MouseEvent.CLICK, myBtnClicked1);

function myBtnClicked1(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!");   
}

my_about.addEventListener(MouseEvent.CLICK, myBtnClicked2);
function myBtnClicked2(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/about-us";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!"); 
}

my_services.addEventListener(MouseEvent.CLICK, myBtnClicked3);
function myBtnClicked3(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/services";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!");  

my_commercial.addEventListener(MouseEvent.CLICK, myBtnClicked4);

function myBtnClicked4(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/commercial";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!");   
}

my_portfolio.addEventListener(MouseEvent.CLICK, myBtnClicked5);
function myBtnClicked5(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/portfolio";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!"); 
}

my_contact.addEventListener(MouseEvent.CLICK, myBtnClicked6);
function myBtnClicked6(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/contact-us";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!");
}
}
}
}
}
}
}
}

This topic has been closed for replies.
Correct answer Ned Murphy

The 1009 error indicates that one of the objects being targeted by your code in frame 37 is out of scope.  This could mean that the object....
 
- is not in the display list
- 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).
 
If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

1 reply

Ned Murphy
Legend
September 14, 2011

Try separating all those into individual listeners/function pairs.  You are effectively nesting a bunch of functions under the first, and nsting function should be avoided.

my_home.addEventListener(MouseEvent.CLICK, myBtnClicked1);

function myBtnClicked1(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!");   
}

}

my_about.addEventListener(MouseEvent.CLICK, myBtnClicked2);
function myBtnClicked2(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/about-us";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!"); 
}

}

my_services.addEventListener(MouseEvent.CLICK, myBtnClicked3);
function myBtnClicked3(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/services";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!"); 

}

}

my_commercial.addEventListener(MouseEvent.CLICK, myBtnClicked4);

function myBtnClicked4(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/commercial";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!");   
}

}

my_portfolio.addEventListener(MouseEvent.CLICK, myBtnClicked5);
function myBtnClicked5(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/portfolio";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!"); 
}

}

my_contact.addEventListener(MouseEvent.CLICK, myBtnClicked6);
function myBtnClicked6(e:MouseEvent):void {
var url:String = "http://www.weedwarriors.co.uk/contact-us";
var request:URLRequest = new URLRequest(url);   
try {
navigateToURL(request, '_self');
} catch (e:Error) {       
trace("Error occurred!");
}
}

DK1120Author
Known Participant
September 14, 2011

hi there

many thanks for that, when try that I get this error?

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at anim_home_fla::mower_anim_1/frame37()

Ned Murphy
Ned MurphyCorrect answer
Legend
September 14, 2011

The 1009 error indicates that one of the objects being targeted by your code in frame 37 is out of scope.  This could mean that the object....
 
- is not in the display list
- 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).
 
If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.