我试过这种方式,但它不会在图像上绘制。只有当我试图在右边界(图像外)绘制它才有效。
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>
更新 如果我喜欢这样,一切都很棒!
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);
答案 0 :(得分:2)
据我所知,你不能直接在图像上画线,你需要画一个UIComponent。
以下链接可以为您提供帮助:
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/