0 Replies Latest reply on Jan 8, 2008 10:02 AM by Tikis_Mikis

    Drawing a line from one shape to another

    Tikis_Mikis Level 1
      So I found out how to create shapes with the Drawing API. I also found out how to draw lines from a point (x1, y1) to a another (x2, y2).

      I am going to try to explain this as easily as i can. I dynamically generate two triangles and add them to a canvas as follows:

      var triangleHeight:uint = 100;
      var triangle:Shape = new Shape();

      // red triangle, starting at point 0, 0
      triangle.graphics.beginFill(0xFF0000);
      triangle.graphics.moveTo(triangleHeight/2, 0);
      triangle.graphics.lineTo(triangleHeight, triangleHeight);
      triangle.graphics.lineTo(0, triangleHeight);
      triangle.graphics.lineTo(triangleHeight/2, 0);

      // green triangle, starting at point 200, 0
      triangle.graphics.beginFill(0x00FF00);
      triangle.graphics.moveTo(200 + triangleHeight/2, 0);
      triangle.graphics.lineTo(200 + triangleHeight, triangleHeight);
      triangle.graphics.lineTo(200, triangleHeight);
      triangle.graphics.lineTo(200 + triangleHeight/2, 0);

      var uiWrapper:UIComponent = new UIComponent();
      uiWrapper.addChild(triangle);
      myCanvas.addChild(uiWrapper);

      So one triagle is red then the one to its right is green. I can certainly connect both triangles by drawing a line between them like this:

      triangle.graphics.lineStyle(1, 0xFF0000);
      triangle.graphics.moveTo(50, 50);
      triangle.graphics.lineTo(230, 50);

      each triangle will have "drag and drop" functionality so heres is my question: how can I assign a point in each triangle so that the drawn line will be redrawn each time a triangle is moved? with the line drawing above that line is static. In toher words I need a dynamically drawn line that will adjust to the position of the triangles. Any ideas/tips/resources????? If lets say instead of triangles I used Button components is there a way to assing "connection points" to the buttons as well???

      Help!