Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a shape via code

Pretty basic question here, but its still got me a little confused..

I have an object(navigation menu bar) that I want to change the colors on with code, so in an updateColor function, I get the bounds of the object (which is a drawing shape contained in a movieclip) and redraw a new shape on top of it with the new color, but I've noticed that the last shape still exists behind this redraw.

I tried using obj.graphics.clear(); before the redraw but that didn't get rid of the original shape. Is there another command that I'm overlooking?

like image 255
Conor Avatar asked Jul 20 '26 08:07

Conor


1 Answers

Unless you drew the object you wish to remove within the same graphics object, clearing won't work. You need to remove the DisplayObject.

Depending on the number of children you can do:

obj.removeChildAt(0);

This also removes movieclips / buttons you placed on the stage manually. If you have a reference to the DisplayObject you wish to remove you can simply do

obj.removeChild(backgroundClip);

Note that you can also change the color of a DisplayObject directly:

import flash.geom.ColorTransform;
...
public var test:MovieClip; //instance on stage
...

var cf:ColorTransform = test.transform.colorTransform;
cf.color = 0xff0000;
test.transform.colorTransform =  cf;
like image 82
Les Avatar answered Jul 23 '26 16:07

Les



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!