6 Replies Latest reply on Jun 20, 2007 10:16 AM by Gil1

    How to detect mouseover of line drawing

    kerst001
      I have a series of lines that I draw onto my canvas. I would like to be able to detect the mouseover for the specific line then based on the line show certain information. I can create a mouseover for a button or object, but am unsure of how to do this for a specific line being drawn on the canvas. Any direction would be great, Thanks!
        • 1. Re: How to detect mouseover of line drawing
          kerst001 Level 1
          anyone have any thoughts?
          • 2. Re: How to detect mouseover of line drawing
            Oddsy
            I haven't checked this out at all so this could be totally wrong but...

            If each line is drawn on its own Sprite, rather than drawing onto the cavnas, you can detect mouseovers on the sprite.
            • 3. Re: How to detect mouseover of line drawing
              kerst001 Level 1
              But if this were the case, and I were to have 90 lines, would that not mean there were then 90 sprites? It seems like response time could summer as a result from this. This may be the only option I have, just want to consider the possibilities.
              • 4. Re: How to detect mouseover of line drawing
                Gil1 Level 1
                Kerst001,

                I did what Oddsy suggested in Flash 8 a while back and it worked just fine.

                Yeah, you will have a sprite for each line, but I don't think that will affect performance much. On the other hand, it will give you a lot of flexibility. for example you can drag the lines, delete individual lines, change colors for each one, etc.

                Gilbert
                • 5. Re: How to detect mouseover of line drawing
                  kerst001 Level 1
                  Gil,

                  Is there any chance you still have some of that code that I could use as a starting point? Thanks!
                  • 6. Re: How to detect mouseover of line drawing
                    Gil1 Level 1
                    I was drawing the line and assigning it to a MovieClip.
                    The code in Flash 8 for the function that does that is:

                    drawLines = function():Void{
                    myColor = this.color_ = 0x000000;
                    myLine = this.linea = 5;

                    if(origin) {
                    x1 = Canvas._xmouse;
                    y1 = Canvas._ymouse;
                    origin = !origin;
                    msg.text ="Move and click the mouse where you want to end the line";
                    msgFormat();
                    } else{
                    x2 = Canvas._xmouse;
                    y2 = Canvas._ymouse;

                    Canvas.createEmptyMovieClip("line"+nLines,Canvas.getNextHighestDepth());
                    Canvas["line"+nLines].lineStyle (myLine, myColor, 100);
                    Canvas["line"+nLines].moveTo (x1,y1);
                    Canvas["line"+nLines].lineTo (x2,y2);
                    Canvas["line"+nLines].p1 = {x:x1, y:y1};
                    Canvas["line"+nLines].p2 = {x:x2, y:y2};
                    gsbTrace("p1= "+Canvas["line"+nLines].p1.x +" p2= "+Canvas["line"+nLines].p2.x);
                    drawing = false;
                    msg.text ="To draw another line, click on 'Draw Routes' again\n\nTo delete the line click on it and then on 'Delete Selected Object'";
                    msgFormat();
                    }
                    nLines ++;

                    for(var sInstance:String in Canvas) {
                    Canvas[sInstance].onPress = function():Void {
                    mSelected = null;
                    lSelected = this;
                    l_selected.text = lSelected._name;
                    index = lSelected._name.substr(1);
                    var myColor:Number = 0xFF0000;
                    lSelected.clear();
                    lSelected.lineStyle (5, myColor, 100);
                    lSelected.moveTo (lSelected.p1.x,lSelected.p1.y);
                    lSelected.lineTo (lSelected.p2.x,lSelected.p2.y);

                    myDragger._visible = false;
                    gsbTrace("lSelected... "+ lSelected);
                    };
                    }
                    }

                    In Flex, instead of creating the line in a MovieClip, you can put it on a sprite (basically a component) using the addChild method.

                    I hope this helps.

                    Gilbert