PDA

View Full Version : help applying drawing api AS to a movieclip


impsvi
11-27-2005, 04:31 PM
hello, ive got stuck trying to do somthing pretty simple.

Using drawing api i have used the following code (below) to allow the user to draw.
The code creates an empty movie clip so the drawing api can work, but this allows the user to draw over everything on screen.

I tried to make it so the code refrenced a movie clip i had on stage instead of creating a empty one, but this did not work. I also tried applying the code inside a movieclip which i placed on stage but this also failed.

Im trying to make it so there is a drawing box on screen (movieclip) and outside of that box the user cannot draw.

How would i edit this code so it works only on a movieclip placed on the stage?

*************************************
_root.createEmptyMovieClip("paintClip", 1);
var thickness:Number = 1;
var colour:Number = 0x000000;
var alpha:Number = 100;
onMouseDown = function () {
paintClip.moveTo(_xmouse, _ymouse);
onMouseMove = function () {
paintClip.lineStyle(thickness, colour, alpha);
paintClip.lineTo(_xmouse, _ymouse);
};
};
onMouseUp = function () {
onMouseMove = null;
};
*************************************

Im using flash8 as2 and the .fla is included.

Thanks,
Vic

amen0
11-27-2005, 04:52 PM
modify ur script like this

var drawingArea = {x:0, y:0, width:500, height:400};
_root.createEmptyMovieClip("paintClip", 1);
var thickness:Number = 1;
var colour:Number = 0x000000;
var alpha:Number = 100;
onMouseDown = function () {
if (((_xmouse>drawingArea.x) && (_xmouse<(drawingArea.x+drawingArea.width))) && ((_ymouse>drawingArea.y) && (_ymouse<(drawingArea.y+drawingArea.height)))) {
paintClip.moveTo(_xmouse, _ymouse);
onMouseMove = function () {
if (((_xmouse>drawingArea.x) && (_xmouse<(drawingArea.x+drawingArea.width))) && ((_ymouse>drawingArea.y) && (_ymouse<(drawingArea.y+drawingArea.height)))) {
paintClip.lineStyle(thickness, colour, alpha);
paintClip.lineTo(_xmouse, _ymouse);
}
};
}
};

impsvi
11-27-2005, 06:24 PM
thank you very much amen0,
that if statement is very usefull.

Suicidal.Banana
11-27-2005, 06:46 PM
ive done it like this
DrawBack.createEmptyMovieClip("myLine", 1);

_parent.onMouseDown = function ()
{
if(_root.drawing == 1) {
_parent.moveTo(_xmouse, _ymouse);
DrawBack.myLine.moveTo(_xmouse, _ymouse);
DrawBack.myLine.lineStyle(6, 0xDDDDDD, 45);
_parent.onMouseMove = function ()
{

Can.gotoAndStop(3);
DrawBack.myLine.lineTo(_xmouse, _ymouse);

};
}
};
_parent.onMouseUp = function ()
{
if(_root.drawing == 1) {
Can.gotoAndStop(2);
_parent.onMouseMove = lineClear;
}
};


the line gets drawn in the movieclip drawback wich is already on the stage