5 Replies Latest reply on Nov 8, 2010 11:17 PM by Flex harUI

    Need help on the simple code

    ChaChaYa

      Hi all,

      In this code, I want to draw by mouse. The code is very simple but failed to work( I can not draw anything in the screen) on my Flex builder 4.

      I really appreciate if you can help me out. Thank you very much in advance.

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

         creationComplete="init()">

      <fx:Declarations>

      <!-- Place non-visual elements (e.g., services, value objects) here -->

      </fx:Declarations>

       

      <fx:Script>

      <![CDATA[

      import flashx.textLayout.events.UpdateCompleteEvent;

       

      import mx.binding.utils.BindingUtils;

      import mx.controls.Alert;

      import mx.managers.CursorManager;

       

      private var mX:Number;

      private var mY:Number;

      private var IsDown:Boolean=false;

      [Bindable] public var _lineSize:int=3;

      [Bindable] public var _lineColor:uint=0xff0000;

       

      private function init():void{

      myPanel.addEventListener(MouseEvent.MOUSE_DOWN,downHandler);

      myPanel.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);

      myPanel.addEventListener(MouseEvent.MOUSE_UP,upHandler);

      BindingUtils.bindProperty(this,"_lineSize",hs,"value");

      BindingUtils.bindProperty(this,"_lineColor",cp,"selectedColor");

      }

       

      private function downHandler(e:MouseEvent):void{

      IsDown=true;

      mX=myPanel.mouseX;

      mY=myPanel.mouseY;

      }

      private function upHandler(e:MouseEvent):void{

      IsDown=false;

      }

       

      private function moveHandler(e:MouseEvent):void{

      if(IsDown){

      var x:Number = myPanel.mouseX;

      var y:Number = myPanel.mouseY;

      myPanel.graphics.lineStyle(_lineSize,_lineColor,1);

      myPanel.graphics.moveTo(mX,mY);

      myPanel.graphics.lineTo(x,y);

      mX=x;

      mY=y;

      }

      }

      ]]>

      </fx:Script>

       

      <mx:Panel width="100%" height="100%">

      <mx:Canvas id="myPanel" x="113.5" y="83" width="100%" height="100%"

         buttonMode="true" borderStyle="solid"/>

       

      <mx:Button label="Clear" click="myPanel.graphics.clear();"/>

      <mx:HSlider id="hs" value="{_lineSize}"/>

      <mx:ColorPicker id="cp" selectedColor="{_lineColor}"/>

      </mx:Panel>

      </s:Application>