Drawing simulation

I got it!
The depth of the mask should be line`s +1.
But I cant understand the code to create the mask.

mask.beginFill(0x000000, 10);
mask.moveTo(0, -14);
mask.lineTo(0, -380);
mask.lineTo(720, 0);
mask.lineTo(720, -14);

This creates a triangule and not a retangule!

[AS]createEmptyMovieClip(“line”, ++depth);
createEmptyMovieClip(“mask”, ++depth);
mask.beginFill(0x000000, 100);
mask.moveTo(20, 0);
mask.lineTo(20, 420);
mask.lineTo(400, 420);
mask.lineTo(400, 0);
mask.lineTo(20, 0);
line.setMask(mask);
line.lineStyle(0);
line.onMouseDown = function() {
this.moveTo(_xmouse, _ymouse);
this.onEnterFrame = function() {
this.lineTo(_xmouse, _ymouse);
};
};
line.onMouseUp = function() {
delete this.onEnterFrame;
};[/AS]

That should work…

Ahmed: Sorry about the same level statement, I just realized what it does… 'doh

lol… kinda tricky eh :stuck_out_tongue:

The mask is ok now, but when I do the first click, a line is created from x=0 and y=0 to x and y mouse positions! Kind of strange!

This is the code I remixed:

// 1. SETTING THINGS
this.createEmptyMovieClip("line", 1)
this.createEmptyMovieClip("mask", 2)
mask.beginFill(0x000000, 100);
mask.moveTo(0, -14);
mask.lineTo(0, -380);
mask.lineTo(720, -380);
mask.lineTo(720, -14);
mask.lineTo(0, -14);
line.setMask(mask);
line.lineStyle(2, 0xFF0000, 80);
line.onMouseDown = function() {
	line.lineTo(_xmouse,_ymouse);
	line.lineStyle(2,0xFF0000,100);
		this.onMouseMove = function(){
			line.lineTo(_xmouse,_ymouse);
			updateAfterEvent();
       }
}
line.onMouseUp = function() {
	this.onMouseMove = null;
}

Now I just want to solve the problem about the first click I reported in the last post.

Im kind of confusing everything. I was testing the lineTo and moveTo onMouseDown event. There are two ways of drawing. If I use lineTo, it creates a line from the last mouseUp event. So there will be just one continuous line. But if I use moveTo, everytime the mouse is up and down again, it will break up the line. Im getting confused in my own explanation. Need to sleep!
Thanks very much for helping me! :thumb:

see u

Here is my new question:
[color=red]Is it possible to do a first click to set the x and y position and on the second click a line is drawn from the first x and y position? And on third click is sets again x and y positions…thsi way I could draw separate lines?[/color]

this might be related … not sure
Math.max(-200, Math.min( _xmouse , 200) );
this gives a value between -200 and +200 that is sometimes the mouse position

onMouseDown=function(){ lineTo(_xmouse,_ymouse);};

but looking at the above code, where should I put it?

linestyle(1);
onMouseDown=function(){ this.lineTo(_xmouse,_ymouse);};

these two lines all by themselves in a movieclip give you the results you want. Is there any thing on top of that you want to add? I think the tough part will be restricting it to within certain bounds.

Hey clownstaples!
This code Ive already used in my code! :thumb: What Im looking for is more advanced tool for drawing straigh lines.
Ill try to explain: ** Im trying to draw a line just in two clicks. But when I press the mouse down again, for the third time, it does not continue drawing, but iniciate a new line. So this way I could draw separate lines! Did u get it?**

Thanks anyway :slight_smile:

every other click will start a line and every other click will finish one?

Heres a rather “simplified” method…

[AS]trigger = false;
this.createEmptyMovieClip(“box”, ++depth);
this.createEmptyMovieClip(“line”, ++depth);
this.createEmptyMovieClip(“dot”, ++depth);
dot.lineStyle(3, 0xFF0000, 100);
dot.lineTo(.15, .45);
dot._visible = false;
line.lineStyle(.25, 0, 100);
line.onMouseDown = function() {
if (box.hitTest(_xmouse, _ymouse, true)) {
if (!trigger) {
this.moveTo(_xmouse, _ymouse);
dot._visible = true;
dot._x=_xmouse, dot._y=_ymouse;
trigger = true;
} else {
this.lineTo(_xmouse, _ymouse);
dot._visible = false;
trigger = false;
}
} else {
dot._visible = false;
trigger = false;
}
};
box.lineStyle(.25, 0x000000, 50);
box.beginFill(0xEEEEEE, 50);
box.moveTo(20, 0);
box.lineTo(20, 420);
box.lineTo(400, 420);
box.lineTo(400, 0);
box.lineTo(20, 0);
box.endFill();[/AS]

Drop that on a frame.

[edit]made a few slight adjustments[/edit]

linestyle(1);
onMouseDown=function(){
if(drawing){
this.lineTo(_xmouse,_ymouse);
drawing=false;
}
else{
this.moveTo(_xmouse,_ymouse);
drawing=true;
}
};

Thats it lostinbeta :thumb:
You are fantastic!!!
LOVE YOU

Could u take a look at my new thread?

I replied to your other thread, but considering what you want there I don’t know how much I can help, I just don’t have the time.

That is one gigantic project you are after, and from the looks of it you may be getting ahead of yourself if you don’t know much about the drawing API in Flash.

I would love to have some explanation about your code!
If you dont mind and have some time to spend?! :slight_smile:

Thanks to [color=red]clownstaples[/color] too!

Ok! No problem. I apreciate.
Do you know about some book or tutorial that could help me?

What does “trigger” do?