Forum Moderators: open
However I need to make this so that the drawing board is only part of the movie, rather than the whole movie, as it is presently. ie I want the drawing pad to sit inside some other graphics.
Here is the code:
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);
}
// this actionscript goes in frame 1
I am able to use flash on a quite basic level and am happy to play with the actionscript, even if I'm not always sure what I'm doing!
Any help would be much appreciated.
ben
<added> alternatively, you could create a new moiveclip (insert > symbol) and add that script to the first frame of the new movieclips timeline.
you can then drag that new movieclip from the library onto the stage with the rest of your graphics etc
you could possibly add an if statement to check the mouses position before drawing, something alongm the lines of:
function mouseDownEvent() {
if (_xmouse>=100&&_xmouse=<400&&_ymouse>=100&&_ymouse=<400){
draw_mc.moveTo(_xmouse, _ymouse);
Mouse.addListener(mouseMoveListener);
}
}
so basically you can only draw if the mouse is between 100 and 400 px along both the x axis and y axis - experiment with co-ordinates to suit.
note: totally untested code. sounds ok in theory but...
This way it's more dynamic and re-usable so you can use it in other applications and with the option of resizing it.
Long story short is so you don't have go in and edit the function every time you need a different size.