-
for loop and navigateToURL problem
Hello,
I'm having problems with creating a for loop to work with my CLICK state with navigateToURL. Can someone please show me the ways of my errors. I'm sure it is simple. Been out of the game for a while and coming in new to AS3. It's kicking my butt a little. Problem areas are in red. The roll states work fine.
Thank You, Jacob
///Button Array
var menuBtns:Array = [mainContent.btnTwitter,mainContent.btnYelp, mainContent.btnFacebook,mainContent.btnPaypal]
var menuLinks:Array = ["http://twitter.com/cakemixaustin","http://www.yelp.com/biz/cakemix-austin", "http://www.facebook.com/profile.php?id=100000647313386&ref=ts"]
//Loop to addListeners to buttons
function addListeners():void
{
for(var i:uint = 0; i < menuBtns.length; i++)
{
//menuBtns[i].addEventListener(MouseEvent.CLICK,clickMenu);
menuBtns[i].addEventListener(MouseEvent.ROLL_OVER,rollOverMen u);
menuBtns[i].addEventListener(MouseEvent.ROLL_OUT,rollOutMenu) ;
//Makes the Hand appear
menuBtns[i].buttonMode = true;
}
for(var j:uint = 0; j < menuLinks.length; j++)
{
menuLinks[j].addEventListener(MouseEvent.CLICK,clickMenu);
}
}
var url:String = menuLinks[j];
var request:URLRequest = new URLRequest(url);
//CLICK Mouse Function
function clickMenu(event:MouseEvent):void{
var button:MovieClip = MovieClip(event.target);
trace(button.name);
button.navigateToURL(url, "_blank");
}
//RollOver Mouse Function
function rollOverMenu(event:MouseEvent):void{
var button:MovieClip = MovieClip(event.target);
trace(button.name);
button.gotoAndPlay("btnRollOver");
}
//RollOut Mouse Function
function rollOutMenu(event:MouseEvent):void{
var button:MovieClip = MovieClip(event.target);
trace(button.name);
button.gotoAndPlay("btnRollOut");
}
addListeners();
-
Code:
///Button Array
var menuBtns:Array=[mainContent.btnTwitter,mainContent.btnYelp,mainContent.btnFacebook];
var menuLinks:Array=["http://twitter.com/cakemixaustin","http://www.yelp.com/biz/cakemix-austin","http://www.facebook.com/profile.php?id=100000647313386&ref=ts"];
//Loop to addListeners to buttons
function addListeners():void {
for (var i:uint = 0; i < menuBtns.length; i++) {
menuBtns[i].addEventListener(MouseEvent.ROLL_OVER,rollOverMenu);
menuBtns[i].addEventListener(MouseEvent.ROLL_OUT,rollOutMenu);
menuBtns[i].addEventListener(MouseEvent.CLICK,clickMenu);
menuBtns[i].num=i;
//Makes the Hand appear
menuBtns[i].buttonMode=true;
}
}
//CLICK Mouse Function
function clickMenu(event:MouseEvent):void {
var button:MovieClip=MovieClip(event.target);
var url:String=menuLinks[button.num];
trace(button.name+" : "+url);
var request:URLRequest=new URLRequest(url);
navigateToURL(request, "_blank");
}
//RollOver Mouse Function
function rollOverMenu(event:MouseEvent):void {
var button:MovieClip=MovieClip(event.target);
button.gotoAndPlay("btnRollOver");
}
//RollOut Mouse Function
function rollOutMenu(event:MouseEvent):void {
var button:MovieClip=MovieClip(event.target);
button.gotoAndPlay("btnRollOut");
}
addListeners();
-
Thank You very much for your help. I would not have figured that out.
I'm getting this error message currently.
instance37 : null
TypeError: Error #2007: Parameter url must be non-null.
at global/flash.net::navigateToURL()
at cakemix_contact_fla::MainTimeline/clickMenu()
-
Make sure you have the same number of items in both arrays.
-
Hmmm.. I didn't alter the code from above. I have three buttons, and three links.
-
First post has four buttons and three links...
-
Thanks once again for your help. I wish that was the problem. I had correct amount of items in each array. Any other ideas.
-
Code:
function clickMenu(event:MouseEvent):void {
var button:MovieClip=MovieClip(event.currentTarget);
var url:String=menuLinks[button.num];
trace(button.name+" : "+url);
var request:URLRequest=new URLRequest(url);
navigateToURL(request, "_blank");
}
-
Works great. Thanks. You made my week.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|