-
changing border of a square
Lets say I have a square like this:
var square:Sprite;
square = new Sprite();
square.graphics.lineStyle(3,0xffffff);
square.graphics.beginFill(0x000000,0);
square.graphics.drawRoundRect(0,0,100,100,20);
square.graphics.endFill();
How can I change the color of the border (i.e lineStyle) from 0xffffff to 0x000000 at runtime, so if a user clicks a button the color of the border changes from black to white.
-
Once it is drawn, you cannot change it. You could clear square's graphics and redraw with the new color.
You could even create a vector of IGraphicsDatas representing each of these drawing steps and replace the color in one of them, then replay the drawing using drawGraphicsData. But that's probably overkill. Just make a function to draw the square and pass the color in.
-
one question about flash, when we use a variable name like square which is a sprite we reassign a new sprite
function sqaureIt(){
square = new Sprite();
square.graphics.lineStyle(3,0xffffff);
square.graphics.beginFill(0x000000,0);
square.graphics.drawRoundRect(0,0,100,100,20);
square.graphics.endFill();
}
Does flash automatically remove the previous sprite from memory? If not whats the best way to go about this?
-
If there are no more references to the old item, it will be eligible for garbage collection. This means it is not on the display list, has no non-weak listeners, and nothing else has a reference to it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|