8 Replies Latest reply on May 21, 2008 12:52 PM by crisbosch

    Tooltip for flash map is misbehaving

      I'm creating a cool flash map with close to 70 locations listed. I created a tooltip function that displays the tooltip when the user rolls over any location button on the stage. Now, I would like to know what is the best way to inject the tooltip info dynamically in my function. So far I have this(see attached code below) and the tooltip function works but the array info is not displayed correctly. I get an "undefined" in the tooltip text area when I roll over the location. What could I be missing?
      Any help is much appreciated. Gracias!

      function showTip(tipText, orient) {
      tooltip._x = _xmouse;
      tooltip._y = _ymouse;
      tooltip._visible = true;
      tooltip.gotoAndStop(orient);
      tooltip.tiptext.text = tipText;
      tooltip.tiptext2.text = tipText;


      onMouseMove = function(){
      tooltip._x = _xmouse;
      tooltip._y = _ymouse;
      updateAfterEvent();
      }
      }

      function hideTip(){
      tooltip._visible = false;
      }

      var b69_text:String = "Espies \n90 Wythe Ave.";

      var array_text:Array = new Array("location0","location1","location2","location3");

      for(i=0; i<5; i++){
      this["b"+i].onRollOver = function(){
      showTip(array_text , 5);
      }
      this["b"+i].onRollOut = function(){
      hideTip();
      }
      }
        • 1. Tooltip for flash map is misbehaving
          Ned Murphy Adobe Community Professional & MVP
          My focus went to this line: showTip(array_text, 5);

          But after posting my reply I noted that the forum may be removing what you intended as being an array index after array_text, treating it as an italic tag... so just to make sure, is there supposed to be a [ i ] showing after array_text in that function call
          • 2. Tooltip for flash map is misbehaving
            Ned Murphy Adobe Community Professional & MVP
            I played with the code in every way I can think of, so to get a reason as to what's being violated we'll need someone with expert knowledge.

            What it appears to boil down to is assigning the rollOver function in a loop with any kind of variable in the showTip function call won't fly, except for the case where it is as it appeared in your posting (with the [ i ] absent)... in which case the entire array displays. If I try to assign the current array value to another variable, within the loop, ahead of defining the function, and use that in the showTip call, it displays the last element of the array for all cases.

            In the event that no one who knows why comes into play, there's another way that you can skin this cat... Place your buttons into movieclips (right click->convert to symbol, etc), and use the loop to assign the tip text to a variable in the movieclip. Your button code within the movieclip can be the same for all cases, calling on that variable.
            • 3. Re:  Tooltip for flash map is misbehaving
              rlc5611 Level 1
              I didn't bother to look at most of your script but the obvious error is one that many people make. The variable "i" only has significance while the for loop is being executed. Once the loop is finished, "i" will have the value of 5 which is outside the bounds of your text array which results in "undefined". You should store a property in your button that you can refer to later such as:

              • 4. Re:  Tooltip for flash map is misbehaving
                Ned Murphy Adobe Community Professional & MVP
                Gee... I didn't realize a button could carry a variable, so I didn't bother trying that approach... I always say, you learn something new every day (with Flash)... rlc has learned me a few today.
                • 5. Re:  Tooltip for flash map is misbehaving
                  rlc5611 Level 1
                  If you don't wish to store a property in the mc/button, a different approach would be to parse the name to extract the number such as:


                  • 6. Re:  Tooltip for flash map is misbehaving
                    Level 1
                    Thanks for the clarification. It works perfectly.
                    • 7. Re:  Tooltip for flash map is misbehaving
                      Level 1
                      Everything I asked for works, but my next logical question is how can I turn this behavior into a class? I understand the OOP principle and I'd like to apply it in this project. Do I need to export the tooltip movie clip also? (this acts as the background and dynamic text holder for the data) The tooltip movie clip is called from the root timeline of my movie. I have prepared the following code as an external .as file. But I know something is off. Any help would be much appreciated. Thanks!
                      • 8. Re:  Tooltip for flash map is misbehaving
                        Level 1
                        Everything I asked for works, but my next logical question is how can I turn this behavior into a class? I understand the OOP principle and I'd like to apply it in this project. Do I need to export the tooltip movie clip also? (this acts as the background and dynamic text holder for the data) The tooltip movie clip is called from the root timeline of my movie. I have prepared the following code as an external .as file. But I know something is off. Any help would be much appreciated. Thanks!