Results 1 to 3 of 3
-
April 13th, 2012, 04:45 AM #1103Registered User
postsAS3: clear a single line graphics from its multiple instance upon click
hello Everybody,
I am trying to delete a single line using graphics.clear() method but it clears all the instance of lines created by lineTo() method. I want to remove a single line upon click from bunch of its multiple instance.
Any advices, suggestions are welcomed.
-
April 13th, 2012, 05:07 AM #2
I think the only way to do this is to store each drawn line into an Array and call the graphics.clear on a specific Array index
As3 / JS/jQuery / HTML5 / CSS(3) / Java(learning) / PHP(learning)
Formerly known as: MJTheOne
-
April 13th, 2012, 11:26 AM #31,391Registered User
postsright MJ, but that would only work if each line were on independent DOs
so another approach might be to store the vertex pairs of each segment an array, clear all, remove/add a segment, then redraw all segments contained in the array
BUT... we also now have this type of functionality with GraphicsPath and graphics.drawGraphicsData()
so you could create a Vector of IGraphicsData Objects, push your line segments as GraphicsPaths, then clear and redraw using the method - something like:
note that the addLine method returns the index of the segment - you could track each line drawn to point at it by id -OR- use the other method for matching by vertex (although i think that quicky method could be improved)Code:import flash.geom.* var data:Vector.<IGraphicsData> = new Vector.<IGraphicsData>(); function addLine( a:Point, b:Point ):int { var line:GraphicsPath = new GraphicsPath( new Vector.<int>(), new Vector.<Number>() ); line.commands.push( 1,2 ); line.data.push( a.x, a.y, b.x, b.y ); return data.push( line ) - 1; } function removeLine( id:int ):void { data.splice( id, 1 ); } function removeSegment( a:Point, b:Point ):void { for( var n:int=0; n<data.length; n++ ) { var pdata:Vector.<Number> = GraphicsPath(data[n]).data; if( a.x==pdata[0] && a.y==pdata[1] && b.x==pdata[2] && b.y==pdata[3] ) removeLine(n); } } function render():void { graphics.clear(); graphics.lineStyle( 1, 0x000000 ); graphics.drawGraphicsData( data ); }Last edited by cbeech; April 13th, 2012 at 11:54 AM.

Reply With Quote

Bookmarks