7 Replies Latest reply on Dec 10, 2017 7:21 PM by kglad

    Tooltip as3 explaination

    iezqandarzulqarnaen Level 1

      Hye guys,

       

      I currently want to learn how to make tooltip via as3.

       

      Hoping you guys can help me to explain what the code function in the code;

       

      import fl.transitions.easing.*;

      import fl.transitions.*;

      mc.addEventListener("mouseOver", mouseRollOver);

      mc.addEventListener("mouseOut", mouseRollOut);

      mc.addEventListener("mouseMove", mouseMove1);

      var tooltip:Tooltip = new Tooltip();

      tooltip.txt.text = "This is a tooltip";

      tooltip.x = stage.mouseX;

      tooltip.y = stage.mouseY - mc.height;

      function mouseRollOver(e:MouseEvent):void {

          addChild(tooltip);

          var myTween:Tween = new Tween(tooltip, "alpha", Regular.easeIn, 0, 1, 0.5, true);

      }

      function mouseRollOut(e:MouseEvent):void {

          removeChild(tooltip);

      }

      function mouseMove1(e:MouseEvent):void {

          tooltip.x = stage.mouseX;

          tooltip.y = stage.mouseY - mc.height;

      }

       

      Thank you

      cc: RandomlyFish, just.emma,

        • 1. Re: Tooltip as3 explaination
          kglad Adobe Community Professional & MVP

          do you have a Tooltip class?  (just  movieclip with a textfield (named txt) is sufficient.)

           

          is that your code?

          • 2. Re: Tooltip as3 explaination
            iezqandarzulqarnaen Level 1

            Yes I have create a Movie Clip with instance & class named "Tooltip" with empty Dynamic Text in it.

             

            This is not my own code, i just copied & pasted from a tutorial (i forgot where).

             

            But I have no idea the function of the code & need someone to help me to explain it so later I can made my own.

             

            and I want make a multi tooltip.

             

            Thanks.

            • 3. Re: Tooltip as3 explaination
              kglad Adobe Community Professional & MVP

              iezqandarzulqarnaen

               

              import fl.transitions.easing.*;

              import fl.transitions.*;

              mc.addEventListener("mouseOver", mouseRollOver);  // adding mouseevent listeners

              mc.addEventListener("mouseOut", mouseRollOut);  //   ""   ""

              mc.addEventListener("mouseMove", mouseMove1);  //  ""  ""

              var tooltip:Tooltip = new Tooltip();  // create a new Tooltip instance

              tooltip.txt.text = "This is a tooltip";  // assign the help text

              tooltip.x = stage.mouseX;  // assign position

              tooltip.y = stage.mouseY - mc.height;  //  ""   ""

              function mouseRollOver(e:MouseEvent):void { 

                  addChild(tooltip);  // add to the display when mc is rolledover

                  var myTween:Tween = new Tween(tooltip, "alpha", Regular.easeIn, 0, 1, 0.5, true);  // tween its alpha so it fades in

              }

              function mouseRollOut(e:MouseEvent):void {

                  removeChild(tooltip);  // remove the tooltip on mouse out

              }

              function mouseMove1(e:MouseEvent):void {

                  tooltip.x = stage.mouseX;   // move the tooltip when the mouse moves

                  tooltip.y = stage.mouseY - mc.height;

              }

               

               

              • 4. Re: Tooltip as3 explaination
                iezqandarzulqarnaen Level 1

                Thanks for the reply @kglad

                 

                So if I put it to more changeable view:

                 

                import fl.transitions.easing.*;

                import fl.transitions.*;

                 

                <movieClip>.addEventListener("mouseOver", <mouseOver function>);  // adding mouseevent listeners

                <movieClip>.addEventListener("mouseOut", <mouseOut function>);  //   ""   ""

                <movieClip>.addEventListener("mouseMove", <mouseMove function>);  //  ""  ""

                 

                var <instance>:<class>= new <class>();  // create a new instance

                <instance>.<dynamicText instance>.text = "This is a tooltip";  // assign the help text

                <instance>.x = stage.mouseX;  // assign position

                <instance>.y = stage.mouseY - <movieClip>.height;  //  ""   ""

                 

                function <mouseOver function>(e:MouseEvent):void { 

                    addChild(<instance>);  // add to the display when mc is rolledover

                    var myTween:Tween = new Tween(<instance>, "alpha", Regular.easeIn, 0, 1, 0.5, true);  // tween its alpha so it fades in

                }

                 

                function <mouseOut function>)(e:MouseEvent):void {

                    removeChild(<instance>);  // remove the tooltip on mouse out

                }

                 

                function <mouseMove function>(e:MouseEvent):void {

                    <instance>.x = stage.mouseX;   // move the tooltip when the mouse moves

                    <instance>.y = stage.mouseY - <movieClip>.height;

                }

                 

                is this correct?

                • 5. Re: Tooltip as3 explaination
                  kglad Adobe Community Professional & MVP

                  that's not valid actionscript.  if it's meant to something else, i don't understand it.

                  • 6. Re: Tooltip as3 explaination
                    iezqandarzulqarnaen Level 1

                    So sorry,

                     

                    forget my previous post.

                     

                    What i need to change if i want to make another tooltip in the same stage.

                    • 7. Re: Tooltip as3 explaination
                      kglad Adobe Community Professional & MVP

                      import fl.transitions.easing.*;

                      import fl.transitions.*;

                      var tooltip:Tooltip;

                      var ttObj:Object={};

                       

                      //call toolTipF and pass whatever displayobject and tooltip string you want

                       

                      function toolTipF(dobj:DisplayObject,s:String):void{

                      tooltip = new Tooltip();  // create a new Tooltip instance

                      tooltip.txt.text = s;  // assign the help text

                      tooltip.x = stage.mouseX;  // assign position

                      tooltip.y = stage.mouseY - mc.height;  //  ""  ""

                      ttObj.dobj=tooltip;

                      obj.addEventListener(MouseEvent.MOUSE_OVER,mouseRollOver);

                      obj.addEventListener(MouseEvent.MOUSE_OUT,mouseRollOut);

                      }

                      function mouseRollOver(e:MouseEvent):void {

                      tooltip=ttObj.e.currentTarget

                          addChild(tooltip);  // add to the display when mc is rolledover

                          var myTween:Tween = new Tween(tooltip, "alpha", Regular.easeIn, 0, 1, 0.5, true);  // tween its alpha so it fades in

                      }

                      function mouseRollOut(e:MouseEvent):void {

                          removeChild(ttObj.e.currentTarget);  // remove the tooltip on mouse out

                      }

                      function mouseMove1(e:MouseEvent):void {

                          tooltip.x = stage.mouseX;  // move the tooltip when the mouse moves

                          tooltip.y = stage.mouseY - mc.height;

                      }