# A program that will let the user to draw a rectangle

**URL:** <https://forum.kirupa.com/t/a-program-that-will-let-the-user-to-draw-a-rectangle/308425>\
**Category:** flash\
**Created:** [April 22, 2010, 4:24pm UTC](https://forum.kirupa.com/t/a-program-that-will-let-the-user-to-draw-a-rectangle/308425 "2010-04-22T16:24:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![royalrapier](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@royalrapier](https://forum.kirupa.com/u/royalrapier)\
**Post date:** [April 22, 2010, 4:24pm UTC](https://forum.kirupa.com/t/a-program-that-will-let-the-user-to-draw-a-rectangle/308425/1 "2010-04-22T16:24:16Z")

</div>

Hi, I’ve been trying to write a simple program that would let the user draw a rectangle, like for example in Paint etc. Could someone please tell me what is wrong with my code? When i compile, it won’t create a rectangle at all.

Here’s the source:

package  
{  
import flash.display.MovieClip;  
import flash.events.Event;  
import flash.events.MouseEvent;

```
public class myRect extends MovieClip
{
    var xx:int=0;
    var yy:int=0;
    var rect:MovieClip=new MovieClip();
    public function myRect()
    {
        stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDownRect,false,0,true);
        stage.addEventListener(MouseEvent.MOUSE_UP,onMouseUpRect,false,0,true);
        addChild(rect);
    }
    private function onMouseDownRect(evt:MouseEvent):void
    {
        stage.removeEventListener(MouseEvent.MOUSE_DOWN,onMouseDownRect);
        rect.graphics.beginFill(0xFF0000);
        rect.graphics.drawRect(mouseX,mouseY,0,0);
        xx=mouseX;yy=mouseY;
        stage.addEventListener(Event.ENTER_FRAME,onLoop,false,0,true);
    }
    private function onMouseUpRect(evt:MouseEvent):void
    {
        rect.graphics.endFill();
        stage.removeEventListener(Event.ENTER_FRAME,onLoop);
    }
    private function onLoop(evt:Event):void
    {
        rect.width=mouseX-xx;
        rect.height=mouseY-yy;
        addChild(rect);
    }
}

```

}
