1 Reply Latest reply on Oct 7, 2013 6:00 AM by Chicken_Mobile

    Logic problem - bind function being stubborn... help?

    Chicken_Mobile

      I have a logic problem in my code that I need help solving,

       

      here's the bit of code which is supposed to set the text, image and link for a symbol used multiple times on the Stage.

       

      var names = ["melz", "brom", "calm", "micj", "mick", "brir", "mato", "brym", "azin", "hugh", "nicl", "bonr", "lisa"];
      var name = null;
      
      
      for(var x = 0; x < names.length; x++){
                name = names[x];
                var initials = (name[0]+""+name[3]).toUpperCase();
                var cursymbol = sym.getSymbol(name);
      
      
                cursymbol.$("name").html(initials);
                cursymbol.$("img").css({"background-image":"url(../"+name+"/team.jpg)"});
      
      
                cursymbol.$("hoveronme").bind("click",function(){ 
                          window.open("../" + name + ".html", "_self");
                });
      
      }
      

       

      The text and image code work, however my problem is with setting the link. It always sets all the symbols to the last name in the names[] array. What I want it to do is to set the link to the personalised name in the array. So the HH button will link to hugh.html and the BM button will link to brym.html etc.

       

      Any ideas? Help would be very appreciated . For now I'm going to play around a bit and see what happens.

        • 1. Re: Logic problem - bind function being stubborn... help?
          Chicken_Mobile Level 1

          Ok so I solved my own problem in around 10 minutes

           

          What I did was use an each loop with a function instead of a for loop. Works perfectly now

           

           

          $.each(names, function( x, name ){
          
               var initials = (name[0]+""+name[3]).toUpperCase();
               var cursymbol = sym.getSymbol(name);
          
          
               cursymbol.$("name").html(initials);
               cursymbol.$("img").css({"background-image":"url(../"+name+"/team.jpg)"});
          
          
               cursymbol.$("hoveronme").bind("click",function(){
                    window.open("../" + name + ".html", "_self");
               });
          });