1
我想实现一些简单的(我想!)但不是。我想借鉴一个形象。我已经创建一个新的组件DrawingImg,延伸S:图片flex如何在图像上绘制
public class DrawingImg extends Image
{
private var isDrawing:Boolean = false;
private var x1:int;
private var y1:int;
private var x2:int;
private var y2:int;
public var drawColor:uint = 0x000000;
public function DrawingImg()
{
super();
addEventListener(FlexEvent.CREATION_COMPLETE, function(event:FlexEvent):void {
erase();
});
addEventListener(MouseEvent.MOUSE_DOWN, function(event:MouseEvent):void {
x1 = mouseX;
y1 = mouseY;
isDrawing = true;
});
addEventListener(MouseEvent.MOUSE_MOVE, function(event:MouseEvent):void {
if (!event.buttonDown){
isDrawing = false;
}
x2 = mouseX;
y2 = mouseY;
if (isDrawing){
graphics.lineStyle(2, drawColor);
graphics.moveTo(x1, y1);
graphics.lineTo(x2, y2);
x1 = x2;
y1 = y2;
}
});
addEventListener(MouseEvent.MOUSE_UP, function(event:MouseEvent):void {
isDrawing = false;
});
}
public function erase():void {
graphics.beginFill(0xffffff, 0.00001);
graphics.drawRect(0, 0, width, height);
graphics.endFill();
}
}
}
这里是我的观点:
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="GiftCertificateView"
actionBarVisible="false" xmlns:local="*">
<local:DrawingImg source="/assets/dessin.png" width="100%" height="100%"/>
</s:View>
这是“近”的工作,当我的鼠标是出图像的,我可以画出我的线,但是当我结束这个图像时,什么都没有出现? 有没有人有想法?
非常感谢。有用。我也尝试过一个扩展“Group”的类,它也可以工作。 – user1300025 2012-04-10 13:55:56