简体   繁体   中英

How to change the color of the just drawed Shape(ActionScript)

i have drawed some figure(circle, rectangle or just a line) and after that i want to change they color without drawing another figure overlaying those, is that possible?

graphics.beginFill(0x000000, 1);
graphics.drawCircle(70, 67, 2);
graphics.drawCircle(90, 67, 2);
graphics.endFill();

after this code is possible to change the color of those circles? lets say some time later...

It is and it isn't. Once you draw that shape it becomes baked into the draw buffer for that frame. If you've drawn it to the main frame-buffer, that's it, no changies. What you CAN do is draw it to a separate instance of a Sprite or MovieClip and use ColorTransform .

var mc:MovieClip=new MovieClip();

mc.graphics.beginFill(0x000000, 1);
mc.graphics.drawCircle(70, 67, 2);
mc.graphics.drawCircle(90, 67, 2);
mc.graphics.endFill();

and later:

var c:ColorTransform = new ColorTransform();
c.color = (Math.random() * 0xFFFFFF);
mc.transform.colorTransform = c;

Putting your shape in a MovieClip also has the advantage of not having to redraw it on every frame manually (clearing the normal frame-buffer won't clear the MovieClip 's) and also means you can move it around easily with mc.x and mc.y .

Just out of curiosity, why can't you set the color when it's drawn?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM