开发者

Drawing over an loaded image with mouse

开发者 https://www.devze.com 2023-02-11 06:41 出处:网络
I tried this way, but it doesn\'t draw on the image. Only if I tries to draw on right border (outside the image) it working.

I tried this way, but it doesn't draw on the image. Only if I tries to draw on right border (outside the image) it working.

private var oldX:Number, oldY:Number; 
private var mode:String = "modeBrush";
   private function onMouseDown(e:MouseEvent):void { 
    oldX = e.localX; 
    ldY = e.localY; 
   } 
   private function onMouseMove(e:MouseEvent):void { 
        if (e.buttonDown) { 
       var g:Graphics = currImg.graphics; 
       var mx:Number = e.localX; 
       var my:Number = e.localY;        
           g.lineStyle(10, 0xFFFF00); 
       g.moveTo(oldX, oldY); 
       g.lineTo(mx, my); 
    }   
        oldX = mx; 
    oldY = my;  
} 
//image i'am loading at runtime by button click

 <s:BorderContainer id="everything" borderStyle="solid"  width="900" height="600">
      <s:Scroller left="2" right="2" top="2" bottom="2">
           <s:Group id="group"> 
         <mx:Image id="currImg" mouseMove="onMouseMove(event)" mouseDown="onMouseDown(event)"/>
           </开发者_高级运维s:Group>
       </s:Scroller>    
     </s:BorderContainer>

UPDATE If I do like this, everything works great!

var line:UIComponent = new UIComponent();
    line.graphics.lineStyle(2, 0x990000, .75);
    line.graphics.beginFill(0x000000);
    line.graphics.moveTo(oldX, oldY);
    line.graphics.lineTo(mx, my);
    currImg.addChild(line);


As I know you cannot draw line directly on a image, you need to draw on a UIComponent.

The following link may help you:

http://groups.google.com/group/macromedia.flex.flex_builder/browse_thread/thread/bbcfc4e3e0a2e133 http://www.axelscript.com/2008/06/11/drawing-in-flex-using-the-uicomponent/

0

精彩评论

暂无评论...
验证码 换一张
取 消