Detecting Clicks on Lines

Hello,
   I am building a canvas application that allows users to drag and drop different icons on the canvas and connect them through edges. I am using the graphics of the canvas to draw these lines.
However, one of my requirements is to detect clicks on the lines and enable users to modify edge properties. Since lines are not first class objects, it is hard to add click listeners on them. I would like to avoid doing my own click detection through MBRs, etc. Here are my questions:
1) Is using the graphics object in the canvas to draw the lines a recommended approach? It seems cumbersome and requires me to maintain too much state
2) Do you have suggestions on how I can detect clicks on these lines without writing my own code to see if each click interested with any of the lines?
Thanks in advance.

Thanks Alex. I will give that a shot. On a related note, I decided to do this in gumbo to learn my way around it. I can't seem to use Sprites properly in gumbo.
I tried the following:
var s: Sprite = new Sprite();
s.graphics.clear();
s.graphics.moveTo(0,0);
s.graphics.lineTo(10,10);
p.addChild(s);
But I get the following error:
Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
at spark.components.supportClasses::SkinnableComponent/addChild()[E:\dev\beta1\frameworks\pr ojects\flex4\src\spark\components\supportClasses\SkinnableComponent.as:953]
at Test/handleCreate()[/Users/ksshams/dev/workspaces/Adobe Flash Builder Beta2/Test/src/Test.mxml:18]
at Test/___Test_Application1_creationComplete()[/Users/ksshams/dev/workspaces/Adobe Flash Builder Beta2/Test/src/Test.mxml:3]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\beta1\frameworks\projects\framework\src\mx\co re\UIComponent.as:11260]
at mx.core::UIComponent/set initialized()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:1513]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\beta1\frameworks\projects\frame work\src\mx\managers\LayoutManager.as:759]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\beta1\frameworks\projec ts\framework\src\mx\managers\LayoutManager.as:1067]

Similar Messages

  • Click a line in query created from SQ01 - Purchase requisition.

    Hi all,
    my problem is: Tcode SQ01, i've created a query where query's fields are:
    purchase order,
    purchase requisition,
    maintenance order.
    In change query phase, menu Goto --> Report assignment
    i've choosed two standard Tcode:
    IW32
    ME53N
    so that when i click a line of my query and chose iw32 i really can change the order clicked on my query but when i choose ME53n i can only display the last purchase requisition displayed e not that I really clicked on my query!
    So, how can i display the purchase requisition clicked on my query?
    Are there someone help me?
    Thanks a lots,
    Alex.

    Hi Phyllis,
    I face the same problem that Alessandro and I've changed the report assignment to the old transaction ME53. Unfortunately, when I click in the purchase requisition the new ME53N is called instead of ME53.
    Do you have any idea why is this happening?
    Thanks in advance for any help.
    Regards,
    Sara

  • ORA-06502 error when clicked on Lines tab in Oracle Service Contracts

    When i query for some contracts and click on Lines Tab,i get ORA-06502 error.
    This is not happenning with all contracts.My ICX: Numeric Characters profile is set to 10.000,00 but the user who created the contracts which were showing error message has ICX: Numeric Characters profile set to 10,000.00.
    If i change my profile option to this users profile option,then i am not getting error in these contracts but getting error when trying to view the contracts which were created by other users who's ICX: Numeric Characters profile is different from mine.
    Plz let me know how can i resolve this issue.
    Looking for your suggessions.
    Thanks,
    Ravi

    CRS Home is indicative of having Oracle clusterware installed. Is this a RAC cluster? Are you running on ASM? How many nodes? etc.
    Please fill in the blanks.

  • How do I put data from every XMLnode related,in separate movieclips when clicking a line in combobox

    How do I put data from every XMLnode related,in separate movieclips when clicking a line in combobox?
    A sample from the XML is like this:
    <Planter>
              <Lauvtre>
                        <Botanisk_navn>Acer campestre</Botanisk_navn>
                        <Norsk_navn>Naverlønn</Norsk_navn>
                        <Farge>Grønn</Farge>
                        <Herdighet>H4</Herdighet>
                        <Høyde>10-15 m</Høyde>
              </Lauvtre>
    I have a combobox where it shows the Botanical name, and the Norwegian name. But the rest of the info has to be shown in separate movieclips.
    Anyone have an idea how to do this? Can I use the trace function maybe? Here is my AS3 code so far:
    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, onLoaded);
    list.addEventListener(Event.CHANGE, itemChange);
    function itemChange(e:Event):void
              ta.text = list.selectedItem.data;
              tb.text = list.selectedItem.label;
    var xml:XML;
    function onLoaded(e:Event):void
              xml = new XML(e.target.data);
              var il:XMLList = xml.Planter.Lauvtre;
              for(var i:uint=0; i<il.length(); i++)
                        list.addItem({data:il.Farge.text()[i] +"\n"+ il.Herdighet.text()[i]+"\n"+ il.Høyde.text()[i],
                                                                label:il.Botanisk_navn.text()[i] +"\n"+ il.Norsk_navn.text()[i]});
    loader.load(new URLRequest("lauvtre.xml"));
    Thanks!
    Rheus.

    Hi! And thank you for helping. Planter is my root node. I tried removing "Planter" from xml.Planter.Lauvtre. It didn't fetch any data then. My code works as is, but what I want the code to do, is to put these 3:
        <Farge>Grønn</Farge>
        <Herdighet>H4</Herdighet>
        <Høyde>10-15 m</Høyde>
    ...into separate textfields.
    It has to be dynamic, so that when I click on one of the plant names in the combobox, the textfields get updated according to what is selected in the combobox.
    I'm pretty new to Actionscript so I have a hard time explaining my problem:
    I want to use the combobox as the menu, that has all the latin plant names listed. When I click on one of the 100 plantnames I want the correlating info from the XML, put in textfields.

  • Media failure was detected at time/line number

    Version: Oracle 10g
    Recently, this error kept popping up on my EM Alert - "Media failure was detected at time/line number". In the EM, it says Critical.
    I looked at http://download.oracle.com/docs/cd/B16240_01/doc/doc.102/e16282/oracle_database_help/oracle_database_alertlogstatus_mediafailureerrors.html and it says no user action required.
    Anyone guidance on what should I check or if I should be doing anything?
    thks.

    Definitely investigate further. I checked the link you posted and indeed I had to read it about 3 times before I understood what it was saying.
    Get onto the database server and search your alert log (bdump directory) if none 11g for media errors and then determine what needs to be done. Hard to say more until you know what the problem is.
    If you needed to test the datafiles then run dbverify (dbv) or my preferred option which ius to export the full database to a file which causes every block to be read or if you do not have a lot of space just pipe it out to /dev/null but ensure you create a logfile.
    John
    www.jhdba.wordpress.com

  • Child is detecting click even though it shouldn't

    Hello once again,
    I technically know how to make this work right, but I'm trying to figure out what I want to do won't work right.
    I have a Child ("treeToChopDetect") appear when a certain other child ("sceneArray[2]") appears on stage. However, I don't want "treeToChopDetect" to be clickable until another child "guy_Bridge"/ "sceneGuyArray[2]" (the character) reaches frame "guy_AtBridgeNormal" on his own timeline.
    However, "treeToChopDetect" seems to be clickable even though the "manager" function is suppose to be constantly telling the "detectArray" that mouseEnabled = false until "sceneGuyArray[2].currentLabel == "guy_AtBridgeNormal"". I keep getting a trace as output if I click on "treeToChopDetect".
    I can keep it from being clickable if I set the condition to include "canClickBoo == false" (which it is until the guy reaches the right frame), but I shouldn't have to do that.
    For all my other arrays I've been able to use my "manager" function to run through them (via "for" loops) and turn mouseEnabled on and off depending on if the guy is on the right frame, but something isn't working correct with this array, for some reason.
    Sorry if that's confusing. I can try to clarify or add more information if necessary. (I have 600+ lines of code so of course I tried to chop out whatever I could.)
    The var and array:
    var treeToChopDetect:TreeToChopDetect = new TreeToChopDetect;
    treeToChopDetect.x = 355;
    treeToChopDetect.y = 75;
    detectArray = [treeToChopDetect];
    The function to detect: (if I add in canClickBoo == true to the stipulation, it runs correctly; however I don't know why I have to do this)
    function detectFunction(event:MouseEvent) {
                        if (treeToChopDetect.hitTestPoint(mouseX, mouseY, true)) {
                            trace("treeToChopDetect");
    These two functions are run when called in other functions, and they turn on and off the ability to click.
    function canClick() {
                    canClickBoo = true;
                    canFunBoo = true;
                function cantClick() {
                    canClickBoo = false;
                    canFunBoo = false;
    main function that adds/removes "outside" children and defines what canClickBoo or canFunBoo means
    function manager(event:Event) {
                    //listen to see what should appear
                    if (stage.contains(sceneArray[2])) {
                        addChild(detectArray[0]);
                        addChild(detectArray[1]);
                    } else if (!stage.contains(sceneArray[2]) && stage.contains(detectArray[0]) && stage.contains(detectArray[1])) {
                        removeChild(detectArray[0]);
                        removeChild(detectArray[1]);
                    //IF canClickBoo is true, able the mouse/turn on buttonMode
                    if (canClickBoo == true) {
                        ... (various other arrays get turned on)
                        for (var im:uint=0; im<detectArray.length; im++) {
                            detectArray[im].mouseEnabled = true;
                            detectArray[im].buttonMode = true;
                        //ELSE IF canClickBoo is false, disable the mouse/turn off buttonMode
                        } else if (canClickBoo == false) {
                            for (var iy:uint=0; iy<detectArray.length; iy++) {
                                detectArray[iy].mouseEnabled = false;
                                detectArray[iy].buttonMode = false;
                   //if the scene and frame are correct, clicks can be heard               
                    for (var jk:uint = 0; jk<sceneArray.length; jk++) {
                        if (stage.contains(sceneArray[jk])
                            && sceneGuyArray[jk].currentLabel == "guy_At"+wordArray[jk]+"Normal") {
                            //trace("canClick");
                            canClick();
                                           // else clicks can't be heard               
                        } else if (stage.contains(sceneArray[jk])
                            && sceneGuyArray[jk].currentLabel != "guy_At"+wordArray[jk]+"Normal") {
                            trace("cantClick");
                            cantClick();

    Hi, tytbone;
    I'm not going to sort through your logic, because, frankly, it's way too complicated. Complicated logic is hard to debug, and the way you've done it is not likely to perform well.
    Try something like this:
    //Not sure what class you've actually applied to the parent,
    //so this name is made up
    //Not applying a Class? Maybe you should start.
    public class ParentClass extends MovieClip {
         //Assuming you've got these on stage an you're going to let Flash populate them
         //mainly because logic to create, add, and position things is tedious and I refuse to write it
         public var treeToChopDetect:MovieClip;
         public var guy_Bridge:MovieClip;
         public function ParentClass() {
              super();
              //added to stage doesn't bubble, use capture
              addEventListener(Event.ADDED_TO_STAGE, initNewChild, true);
         protected function initNewChild(e:Event):void {
              var newChild:MovieClip = e.target as MovieClip;
              if (newChild) {
                   switch(newChild.name) {
                        case 'treeToChopDetect':
                             mouseChildren = false;
                             mouseEnabled = false;
                             break;
                        case 'guy_Bridge':
                             //find relevant frame
                             var frameNum:int = -1;
                             for each (var frameLabel:FrameLabel in newChild.currentFrameLabels) {
                                  if (frameLabel.name=='guy_AtBridgeNormal') {
                                       frameNum = frameLabel.frame -1;
                                       break;
                             if (frameNum > -1) {
                                  //could do this on the timeline of the child mc or with 
                                  //a base class...this is just for illustration purposes
                                  //tell guy at bridge to dispatch this event when he gets to the frame
                                  newChild.addFrameScript(frameNum, function(){dispatchEvent(new Event('guy_AtBridgeNormal'))});
                                  //listen for that event so you can unlock the tree
                                  newChild.addEventListener('guy_AtBridgeNormal', unlockTree);
                        }//end case
                   }//end if the child was actually a movie clip
              }//end init
              protected function unlockTree(e:Event):void {
                   guy_Bridge.removeEventListener('guy_AtBridgeNormal', unlockTree);
                   treeToChopDetect.mouseEnabled = true;
                   treeToChopDetect.addEventListener(MouseEvent.CLICK, onTreeChop);
              protected function onTreeChop(e:Event):void {
                    //do stuff

  • How to detect mouseover of line drawing

    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!

    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

  • BSP error when clicking on line item in SUS :Buffer table not up to date

    Hi Experts,
    I'm having a problem in SUS Portal. When i click on a line item of a PO to display the actual line item or see more details, i get a buffer table out of date error. I saw a thread with a similar issue where it says problem resolved but haven't had any luck getting a response from the poster, so I'm putting this question out there to everyone.
    Related Post
    Buffer table not up to date in SUS
    More details on error...
    Exception Class CX_BBP_PD_ABORT
    Error Name 
    Program SAPLBBP_PDH
    Include LBBP_PDHU08
    Line 81 
    Long text Buffer table not up-to-date {}
    Regards,
    JD
    Edited by: julian.k. drummond on Apr 13, 2010 6:46 PM

    Hi Julian,
    Please give the system some time and try again. It should work.
    Thanks
    Hari

  • Detecting clicked column in JTable (with JCheckBox in column)

    I am struggling with something that seems like it should be so simple, but it doesn't work as I expect;
    I have a table with 5 columns, the 5th column is a CheckBox. What I need to do is detect when the 5th column changes, ie. the check box is clicked;
    If I use a MouseListener on the table, and derive the table from the event, the column that I get back from getSelectedColumn() is -1, which is not conclusive. I assume this is because clicking the check box is not actually selecting the column.
    I implemented a TableModelListener as follow;
    tableModel.addTableModelListener(new TableModelListener()
    public void tableChanged(TableModelEvent e)
    System.out.println("Changed Column is " + e.getColumn() + " " + e.getFirstRow());
    This seems to do the same as before, and gives a first row of 0 and selected column of -1. Once again inconclusive.
    The cell as I say is rendered as a JCheckBox, the data in the table model obviously being Boolean.
    Can anyone suggest how I can determine if my column with a Check Box in has been clicked, and if so, which Row? (I have thought about overriding JCheckBox, but this seems more work than necessary)
    Thanks in anticipation

    You need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html]
    that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on
    the information provided.
    Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting] so the posted code retains its original formatting.

  • Delayed response to keystrokes after clicking on line

    Does anyone else have this same problem. When I click on a line of type in Pages to make an edit  and then try to type it takes a few seconds to respond. I noticed it originally working on my 2009 15" Macbook Pro, but I've upgraded to a Retina Display and it still occurs.

    I can't say I've particularly noticed in Pages, but I do in Safari & Mail on my Macs running 10.8.2. Finder seems to "beach ball" frequently. I suggest leaving feedback for Pages & OS X.

  • Detect click and coordinates on a PDA

    Hello everybody,
    I'm trying to detect a stylus click on a picture and the coordinates of the click on a PocketPC 2002 PDA. In the PC, this works fine with a "mouse down" event for a picture, which detects the click and the coordinates, but this event is not supported in the PDA module (ver 7.0). Another option I found for the PC is using the LV windows message queue DLL, but this is an especially written DLL and I wouldn't know how to write one for windows, let alone for windows CE, and - to make matters worse - I don't know the equivalent of User32.dll in CE. Does anyone have any suggestions?
    Thanks in advance.
    Try to take over the world!

    I managed to find that the Getmessage function allows you to access the message queue, and I found 2 files which may be relevant:
    1. coredll.dll (which as I understand from the documentation is supposed to hold the function) in "C:\Windows CE Tools\wce300\MS Pocket PC\emulation\palm300\windows".
    2. coredll.lib in "C:\Windows CE Tools\wce300\MS Pocket PC\lib\arm" which is supposed to the file to link to. There's also one in "C:\Windows CE Tools\wce300\Pocket PC 2002\lib\arm".
    When I used this coredll.dll I found a GetMessageW function and I've managed to use this on the PC to detect the click and the coordinates (when I used this DLL and was targeting the PC, a Pocket PC 2000 emulator came up and the origin for the coordinates was it's top-left corner).
    When I try to build the application (with and without the lib file), I get the error that says GetMessageW is a missing VI or C file. I attached the VI which works fine on the PC.
    Try to take over the world!
    Attachments:
    getmessage2.vi ‏30 KB

  • Detecting Click on an MC inside an attached movieclip

    I'm working with a MovieClip ("mainMenuItem") that is linked to a Class ("GenericMenuItem.as") that uses attachMovie to add another movieclip ("Arrow") to mainMenuItem as follows:
    mcArrow = this.attachMovie(prefix+"Arrow", "_Arrow_symbol", this.getNextHighestDepth());
    I'm able to use on(release) within the Class definition to capture clicks on the mainMenuItem component, but haven't been able to find a way to detect a click on the "Arrow" library item that gets attached to that component.
    Any thoughts?

    Thanks...GenericMenuItem (the class linked to mainMenuItem, which itself doesn't have any code) doesn't have any on(release) actions inside it now. I've tried creating a separate Arrow.as class and linking it to that Arrow MovieClip symbol. I'm able to trace output inside the constructor for the Arrow class, but haven't had any luck creating an onPress/onRelease function that works there (I've tried a "this.onPress = Delegate.create(this,function()..." in the constructor, and a "public function onRelease()" in the class body without any luck in either case. I also tried adding "mcArrow.onRelease = function()" below instantiation for mcArrow in the GenericMenuItem.as class, where this is attached (ensuring that the onRelease action occurs in either the Arrow.as class or the GenericMenuItem.as, but not in both places simultaneously, to avoid conflicts). In all cases, I haven't been able to trace anything out on a click action, so don't believe it is handling clicks for this.
    I'd be happy to send over project files if you'd like to take a look. Getting some pressure from a client to get this working, so any help you can provide would be immensely appreciated.
    Any thoughts?

  • Detecting click ( single and double) on row (displayed using iterator)

    Hello All,
    I am using jdev 11.1.1.6
    I am displaying a list as below.
                                   <trh:tableLayout>
                                        <af:iterator value="#{pageFlowScope.Bean.List}" var="temp">
                                         <trh:rowLayout>
                                          <trh:cellFormat>
                                           <af:outputText value="#{temp.value1}"/>
                                          </trh:cellFormat>
                                          <trh:cellFormat>
                                           <af:outputText value="#{temp.value2}"/>
                                          </trh:cellFormat>
                                          <trh:cellFormat>
                                           <af:outputText value="#{temp.value3}"/>
                                          </trh:cellFormat>
                                          <trh:cellFormat>
                                           <af:outputText value="#{temp.value4}"/>
                                          </trh:cellFormat>
                                        </trh:rowLayout>
                                        </af:iterator>
                                      </trh:tableLayout>
    My requirement is, when user clicks on a row, that row should be detected in backend and those value will be used.
    My requirement is, On single click row should be detected(in backend/bean)
    On double click, the values is saved(in backend/bean).
    How can i detect single and double click on a particular row ?

    I have updated the code as below, single click and double click are getting detected on a row
        <af:resource type="javascript">
                function singleClick(){
                    alert("Single Click");
                function doubleClick(){
                    alert("Double Click");
        </af:resource>
                                   <trh:tableLayout>
                                        <af:iterator value="#{pageFlowScope.Bean.List}" var="temp" onclick="singleClick()" ondblclick="doubleClick()">
                                         <trh:rowLayout>
                                          <trh:cellFormat>
                                           <af:outputText value="#{temp.value1}"/>
                                          </trh:cellFormat>
                                          <trh:cellFormat>
                                           <af:outputText value="#{temp.value2}"/>
                                          </trh:cellFormat>
                                          <trh:cellFormat>
                                           <af:outputText value="#{temp.value3}"/>
                                          </trh:cellFormat>
                                          <trh:cellFormat>
                                           <af:outputText value="#{temp.value4}"/>
                                          </trh:cellFormat>
                                        </trh:rowLayout>
                                        </af:iterator>
                                      </trh:tableLayout>
    Now,
    suppose i have following values for some/any row,
    value1=20, value2="abc", value3=009, value4="Language" 
    How can i retrieve these values in java script (if in backing bean then very good)

  • Detecting clicks over a particular region in the frame

    Hey!
    I need to detect whether te user clicked over a particular region in my frame.. something delimited by a poligon... or something like that..
    some ideas?
    thank you in advance!

    Thx for your attention but in this case it wont work 'cause.. I didnt mention but there will be several images in the screen... getPixelColor will return black regardless of what image I clicked on.
    What I really needed is detecting the click over a particular region in the screen!
    thank you

  • Hit detection between a line and a UIView?

    Hi all,
    I'm trying to figure out if a UIView I've got on the screen is intersecting a line I'm drawing.
    Here's the code for drawRect:
    -(void)drawRect:(CGRect)rect
    // Get the current graphics context and clear it
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextClipToRect(ctx, CGRectMake(0, 0, 240, 320));
    CGContextClearRect(ctx, rect);
    // The line style
    CGContextSetLineWidth(ctx, 3.0);
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetRGBStrokeColor(ctx, 1.0, 1.0, 1.0, 1.0);
    // Create the line
    CGContextMoveToPoint(ctx, source.x, source.y);
    CGContextAddLineToPoint(ctx, dest.x, dest.y);
    // Draw the line
    CGContextDrawPath(ctx, kCGPathStroke);
    CGContextStrokePath(ctx);
    That draws a line from and to wherever I need it, but when I draw it over a UIView that's already on the screen, I need to know if the centre point of the UIView is on that line. So, if you have a line going from 0,0 to 10,10, you have points at 1,1 2,2 3,3 ... 10,10. If the centre point of the UIView is at, say, 3,3, it would be on that line.
    I've seen use of the CGContextPathContainsPoint method, but I can't get it working - my line doesn't draw. Here's the code for drawRect:
    -(void)drawRect:(CGRect)rect
    // Get the current graphics context and clear it
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextClipToRect(ctx, CGRectMake(0, 0, 240, 320));
    CGContextClearRect(ctx, rect);
    // The line style
    CGContextSetLineWidth(ctx, 3.0);
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetRGBStrokeColor(ctx, 1.0, 1.0, 1.0, 1.0);
    // Create the path
    CGMutablePathRef linePath = CGPathCreateMutable();
    // Move to the source point and add a line to the destination point
    CGPathMoveToPoint(linePath, NULL, source.x, source.y);
    CGPathAddLineToPoint(linePath, NULL, dest.x, dest.y);
    // Draw the line
    CGPathDrawingMode(kCGPathStroke);
    CGContextDrawPath(ctx, kCGPathStroke);
    CGContextStrokePath(ctx);
    // Save the graphics state before doing the hit detection
    CGContextSaveGState(ctx);
    CGPathRef path = linePath;
    CGContextAddPath(ctx, path);
    if(CGContextPathContainsPoint(ctx, baddie, kCGPathStroke)) {
    NSLog(@"Yes");
    CGContextRestoreGState(ctx);
    I'm clearly doing something wrong here, but I can't quite figure it out.
    Any help much appreciated!

    I'm tearing my hair out with this. This is simple maths!!! Every point I put into the formula works fine, but when it's in code it fails. I think it's something to do with the frame I'm using...
    This is set in the init method:
    CGRect frame = CGRectMake(40.0, 60.0, 240.0, 320.0);
    The source and destination of the line I'm drawing, and the point I want to check (myPoint) are passed in and set up as follows (in their respective setter methods):
    source = CGPointMake(pos.x - 40.0, pos.y - 60.0);
    dest = CGPointMake(pos.x - 40.0, pos.y - 60.0);
    myPoint = CGPointMake(pos.x - 40.0, pos.y - 60.0);
    They have 40 and 60 pixels removed as the co-ords I'm passing in are the location on the iPhone screen (320x480). I have to subtract those values to get the top-left corner of the frame I'm drawing into, i.e. 40, 60 on the screen is actually 0, 0 of the frame.
    Now I draw the line in the drawRect method:
    CGMutablePathRef linePath = CGPathCreateMutable();
    CGPathMoveToPoint(linePath, NULL, source.x, source.y);
    CGPathAddLineToPoint(linePath, NULL, dest.x, dest.y);
    And here's where I check whether the point has touched the line:
    float m = (source.y - dest.y) / (source.x - dest.x);
    float y = (m * (source.x - myPoint.x)) + myPoint.y;
    if((y >= source.y - 3) && (y <= source.y + 3) && (myPoint.x >= source.x) && (myPoint.x <= dest.x)) // ±3 pixels for tolerance
    NSLog(@"Point hit the line!");
    What am I doing wrong?!
    The whole premise of my game rests on this one simple little problem. I've spent two weeks writing the rest of it, and a week writing THIS one part! Grrr.
    Any help much appreciated. If I can't get this done within a week, pop along to London and see a grown man cry.

Maybe you are looking for