On 5/5/07, williamkusumo <[EMAIL PROTECTED]> wrote:
> Please forgive this stupid question. I can't seem to figure out how to
> draw a simple rectangle in a Flex app...:(
>
> I know it involve the graphics object and I have to call drawRect at
> some point. But where do I put this code, and how do I attach this
> rectangle into one of the container?

Here's a simple component that draws a 100x100 rectangle.

  package {
    import flash.display.*;
    import mx.core.*;

    public class RectangleComponent extends UIComponent {
      override protected function updateDisplayList(w:Number, h:Number):void
      {
        super.updateDisplayList();

        var g:Graphics = this.graphics;
        g.clear();
        g.beginFill(0xFF0000);
        g.drawRect(0, 0, w, h);
        g.endFill();
      }
    }
  }

In your application's MXML code:

 <mx:VBox>
   <local:RectangleComponent xmlns:local="*" width="100" height="100" />
 </mx:VBox>

Note that in Flex components should ideally delegate any graphics work
to a "skin" class, and any colours, etc., should come from CSS styles
(as opposed to being hard-coded in the component's code).

http://livedocs.adobe.com/flex/2/langref/flash/display/Graphics.html

Reply via email to