8/28/2010 10:46:40 AM
Title:
Pen and Eraser tool in Flex
Can any one help me to develop Pen and Eraser tools in Flex......
Please help me....
Thanks in Advance
8/28/2010 11:08:11 AM
to create a pen tool in flash you can use the graphics class , see the following code. The below code just draw line from one point to the next as the mouse moves. on mouse down we start the drawing code and on release stop the drawing code. Actually we cannot erase a line but the work around is to set the line color to white. When you draw a white line over your black it will look like erased.
init();
stop();
//
function init() {
initDrawing();
initMouse();
}
function initDrawing() {
createEmptyMovieClip("draw_mc", 10);
draw_mc.lineStyle(2, 0x000000);
createEmptyMovieClip("temp_mc", 20);
}
function initMouse() {
mouseMoveListener = new Object();
mouseMoveListener.onMouseMove = function() {
mouseMoveEvent();
};
//
mouseClickListener = new Object();
mouseClickListener.onMouseDown = function() {
mouseDownEvent();
};
mouseClickListener.onMouseUp = function() {
mouseUpEvent();
};
Mouse.addListener(mouseClickListener);
}
function mouseDownEvent() {
draw_mc.moveTo(_xmouse, _ymouse);
Mouse.addListener(mouseMoveListener);
}
function mouseUpEvent() {
temp_mc.clear();
Mouse.removeListener(mouseMoveListener);
}
function mouseMoveEvent() {
// Remove any previous drawing
temp_mc.clear();
// Draw dot at End Point
temp_mc.lineStyle(6, 0x00ff00);
temp_mc.moveTo(_xmouse, _ymouse);
temp_mc.lineTo(_xmouse + 0.5, _ymouse);
// Draw line segment
draw_mc.lineTo(_xmouse, _ymouse);
}
8/28/2010 11:11:12 AM
check this link for creating freehand drawing or pen tool using actionscript 3
http://www.flashandmath.com/basic/mousedraw2/index.html