Drawing methods and constraining with hitTest

Thanks to the samples and stuff on this board and other places online, I’ve got the beginnings of a nice little online app that will eventually be used to do measurements on medical images. This really isn’t that relevant to the problem I’ve got though.

This has got to be simple, but I can’t get it to work.

The file is structured as following:

-main stage has an MC into which a medical image is loaded from disk (just a jpeg)
-one layer above that is the “canvas” MC. This MC has two layers, a simple square border and the code to enable the straight line drawing methods. Because we are later going to do calculations on the lines, the drawing space needs to be in proper alignment (coordinates-wise) with the actual image. Hence by having the code for the drawing methods in this MC, things line up nicely (i.e. clicking in the upper left of the image registers as 0,0)

Now, all I want to do is simply constrain the ability to draw within that 400x400px canvas area on screen. I’ve tried a few dozen permutations on hitTesting the canvas area, and everything I try simply knocks out the ability to draw anything at all. It’s probably just pathing issues, but I can’t get it.

What I want is probably an if/else statement that checks to see if the mouse is in that area, and if so, lets you do the drawing method. If not, nothing should happen

Any help guys? I’d really appreciate it.

:q:

can anybody suggest some help with this? I know you guys can handle this!

help a stupid graphic designer become more of a programmer!

You could use the [font=courier new]Math.min()[/font] and [font=courier new]Math.max()[/font] methods to constrain the values. :slight_smile:

Try something like this:

var x = Math.min(Math.max(this._xmouse, 0), 400);
var y = Math.min(Math.max(this._ymouse, 0), 400);
this.lineTo(x, y);

thaks for the suggestion. I actually didn’t use that, precisely, but instead just did a check on the mouse position on the stage and that worked. Also fogured out some other stuff in the process.

Now I just have to get it writing out the start and end XY coords of the lines that I draw and logging those somehow.