topical media & game development 
  
 
 
 
 
  
    
    
  
sample-flex-draw-box.mx
sample-flex-draw-box.mx
[swf]
 
 flex
  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
  
      <mx:Script>
          <![CDATA[
  
              import mx.containers.Canvas;
  
              private var x1:uint;
              private var y1:uint;
              private var x2:uint;
              private var y2:uint;
  
              private var isDrawing:Boolean = false;
  
              private function canvas_mouseDown(evt:MouseEvent):void {
                  isDrawing = true;
                  x1 = evt.localX;
                  y1 = evt.localY;
              }
  
              private function canvas_mouseUp(evt:MouseEvent):void {
                  isDrawing = false;
                  x2 = evt.localX;
                  y2 = evt.localY;
  
                  var w:uint = x2 - x1;
                  var h:uint = y2 - y1;
  
                  var can:Box = evt.currentTarget as Box;
                  can.graphics.beginFill(0xFF0000, 0.4);
                  can.graphics.drawRect(x1, y1, w, h);
                  can.graphics.endFill();
  
                  trace(x1, y1, x2, y2);
              }
          ]]>
      </mx:Script>
  
      <mx:Canvas id="canvas"
              backgroundColor="white"
              width="100%"
              height="100%">
          <mx:Box id="box"
                  width="100%"
                  height="100%"
                  mouseDown="canvas_mouseDown(event);"
                  mouseUp="canvas_mouseUp(event);" />
      </mx:Canvas>
  
  </mx:Application>
  
  
  
  
(C) Æliens 
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. 
In case of other copyright issues, contact the author.