Hello Arpan,
There's nothing wrong with the way you have done it. Consider, if you
create child components for each of the rectangles, you will have to
create a new class and paramatise it so they know what colour to
draw, then you will have to instantiate them, using up memory and
cycles, then you will have to write code to position them and manage
them. Is there any added value or functionality in that approach
which justifies it versus what you have now?
One possible advantage is that you will get layering functionality.
Do you need that?
There is some middle ground. You can create a class which manages the
drawing of the rectangles but which isn't actually a sprite subclass.
It could just be a regular object which you can use to draw within
the context of your UIComponent. I have used this technique for
instance to draw grid lines on a custom chart like component where I
wanted to break up the drawing logic but didn't want to create sub-
components.
The only reason for this is to manage complexity. What you have is
perfectly valid. Remember to g.clear() at the beginning unless you
want to smear your component when you move or resize it.
Cheers,
Lach
On 01/12/2006, at 6:51 PM, arpan srivastava wrote:
Hi,
I have to draw 5 rectangle inside a class extending
UIComponent. I have done this :
// Draw first base rectangle
g.beginFill(baseRectColor1);
g.drawRect(0,baseY,bRW1,baseRectHeight);
g.endFill();
// Draw second base rectangle
g.beginFill(baseRectColor2);
g.drawRect(bRW1,baseY,bRW2,baseRectHeight);
g.endFill();
// Draw third base rectangle
g.beginFill(baseRectColor3);
g.drawRect(bRW2 + bRW1,baseY,bRW3,baseRectHeight);
g.endFill();
is this approach ok or should I create new sprite object for
each rectangle and add it to the class. ?