A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: for loop and navigateToURL problem

  1. #1
    Junior Member
    Join Date
    Jan 2006
    Posts
    24

    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();

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    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();

  3. #3
    Junior Member
    Join Date
    Jan 2006
    Posts
    24
    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()

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Make sure you have the same number of items in both arrays.

  5. #5
    Junior Member
    Join Date
    Jan 2006
    Posts
    24
    Hmmm.. I didn't alter the code from above. I have three buttons, and three links.

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    First post has four buttons and three links...

  7. #7
    Junior Member
    Join Date
    Jan 2006
    Posts
    24
    Thanks once again for your help. I wish that was the problem. I had correct amount of items in each array. Any other ideas.

  8. #8
    :
    Join Date
    Dec 2002
    Posts
    3,518
    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");
    }

  9. #9
    Junior Member
    Join Date
    Jan 2006
    Posts
    24
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center