Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 3 of 3

Thread: AS3: clear a single line graphics from its multiple instance upon click

  1. #1

    AS3: 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.

  2. #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) / PHP (intermediate)

  3. #3
    Registered User
    right 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:
    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.lineStyle( 1, 0x000000 );
        graphics.drawGraphicsData( data );
    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)
    Last edited by cbeech; April 13th, 2012 at 11:54 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012