I have drawn a series of lines using flash's graphics.lineTo command, and placed them in an array to be referenced later. Based on certain user interactions, the clips that hold these lines can be shifted to the right, causing the lines to move with them, no longer connecting to the point they originally connected to. So I need to extend the lines by the amount their parent clip was shifted (I've called this incVal). So what I need to do is find the point at which each of these lines ended at, and draw from that point to the left by incVal. How do I get that ending point of the line?
This is my code:
To draw line and add it both to the clip and to an array for future reference:
line.graphics.lineTo(localPoint.x,localPoint.y-10);
membersRef.addChild(line);
parallelArr.push(line);
To reference the line later by looping through the array:
function extendParallels(incVal):void {
for (var i=0;开发者_如何学编程i<parallelArr.length;i++){
trace (parallelArr[i]);
//need to extend line with code here.
}
}
You can't get the graphical endpoints exactly from the sprite in an easy way. You should consider to save the end point in a variable.
var p:Point = new Point(localPoint.x, localPoint.y-10); // flash.geom.Point
And in parallelArr
you could save an object which holds a reference to this point and to the DisplayObject where your line is drawn on.
Change your logic a little bit, and you'll be set. Store a point in your parallelArr array, for reference later.
Somewhat like:
//during dynaminc population
addLine(localPoint.x, localPoint.y);
private function addLine(pX:int, pY:int):void
{
var nPoint:Point = new Point(pX, pY);
line.graphics.lineTo(nPoint.x, nPoint.y-10);
membersRef.addChild(line);
parallelArr.push(nPoint);
}
This gives you access to the state that created the line, and avoids trying to gather it from the line itself. This would be especially complicated if you had any filter applied to the line, as flash immediately renders it as a bitmap...
精彩评论