views:

352

answers:

2

I'm working on an application where I'm drawing some rectangles on the screen, and then will need to manipulate the shapes (change their size, location). I tried to do something with .drawRect and clearing the shape each time I was manipulating it, but the RAM usage was spiking and then falling (presumeably because i keep reinitializing a new component and then removing it, and garbage collection was cleaning it out). This seems like its probably not the most efficient way to do it.

Is there a way for me to just create a shape once, and then move it around on a canvas (and change its width and height without all this RAM usage?

A: 

If all you're doing is changing it's offsets, and adjusting it's width and height without needing to fundamentally change the structure of the shape (such as rounding the corners of a rectangle of some such) you should be able to just maintain a reference to the Shape and adjust it's x, y, scaleX, scaleY properties to effect the changes.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#scaleX

JStriedl
A: 

You can try Degrafa to draw the rectangle.

To move the rectangle:

  • Changing the x and y or height and width property of the shape
  • Using the Flex Move Effect
Brandon