3 Replies Latest reply: Apr 19, 2011 10:15 AM by kglad RSS

    remove then add a Sprite clears its graphics.lineStyle

    eprevot123 Community Member

      Hi

      I have a Sprite containing another Sprite that is a blue rectangle :

      var rectangle:Sprite = new Sprite();
      rectangle.graphics.lineStyle(2, 0x0000FF);
      rectangle.graphics.drawRect(0, 0, 50, 100);
      addChild(rectangle);

       

      Then somewhere in my code I want to take a snapshot of the Sprite without the rectangle but I want the rectangle to stay in the Sprite though.

      I don't know how or event if it's possible to copy the Sprite, so instead, I tried to remove the rectangle, take the snapshot, then re-add the rectangle :

      var rectangle:Sprite = mySprite.removeChildAt(rectangleIndex);

      var bmp:BitmapData = new BitmapData(mySprite.width, mySprite.height);

      bmp.draw(mySprite);

      mySprite.addChild(rectangle);

       

      But then the rectangle is not blue anymore but black. Like the sprite.graphics lineStyle is cleared.

      Do you know how I can keep the lineStyle or do you have another idea ?