Confining mouse actions to MC on stage, v2

Two part question, please bear with me.

Q1. Trying a different method than before to draw straight lines between mouse clicks, confined WITHIN a movie clip on the stage whose instance named “mc_border”. I have a separate mc adjacent to mc_border which acts as a simple color picker, setting a var “currentColor”…which is why I don’t want this drawing routine to use the entire stage. Here’s the code:


var x1:Number=NaN;
var y1:Number=NaN;
var lines:Array=new Array;
stage.addEventListener(MouseEvent.CLICK,setStart);

function setStart(e:MouseEvent):void {
lines.push(new Sprite);
stage.addChild(lines[lines.length-1]);
x1=mouseX;
y1=mouseY;
stage.removeEventListener(MouseEvent.CLICK,setStart);
stage.addEventListener(MouseEvent.MOUSE_MOVE,drawLine);
stage.addEventListener(MouseEvent.CLICK,setEnd);
}

function drawLine(e:MouseEvent):void {
lines[lines.length-1].graphics.clear();
lines[lines.length-1].graphics.lineStyle(2,currentColor);
lines[lines.length-1].graphics.moveTo(x1,y1);
lines[lines.length-1].graphics.lineTo(mouseX,mouseY);
}

function setEnd(e:MouseEvent):void {
	stage.removeEventListener(MouseEvent.CLICK,setEnd) ;
	stage.removeEventListener(MouseEvent.MOUSE_MOVE,drawLine);
	stage.addEventListener(MouseEvent.CLICK,setStart);
}

This works to the point where I can draw my lines (one click to start, second click to stop) anywhere on the stage, including the color picker mc. I’ve made the following changes to the mouse events that make sense to me, but it does not work…

var x1:Number=NaN;
var y1:Number=NaN;
var lines:Array=new Array;
mc_border.addEventListener(MouseEvent.CLICK,setStart);

function setStart(e:MouseEvent):void {
lines.push(new Sprite);
stage.addChild(lines[lines.length-1]);
x1=mouseX;
y1=mouseY;
mc_border.removeEventListener(MouseEvent.CLICK,setStart);
stage.addEventListener(MouseEvent.MOUSE_MOVE,drawLine);
mc_border.addEventListener(MouseEvent.CLICK,setEnd);
}

function drawLine(e:MouseEvent):void {
lines[lines.length-1].graphics.clear();
lines[lines.length-1].graphics.lineStyle(2,currentColor);
lines[lines.length-1].graphics.moveTo(x1,y1);
lines[lines.length-1].graphics.lineTo(mouseX,mouseY);
}

function setEnd(e:MouseEvent):void {
	mc_border.removeEventListener(MouseEvent.CLICK,setEnd) ;
	stage.removeEventListener(MouseEvent.MOUSE_MOVE,drawLine);
	mc_border.addEventListener(MouseEvent.CLICK,setStart);
}

What am I missing here?

Q2: The mc_border clip also contains simple buttons which get very glitchy when rolled over while trying to draw the lines. This project is a simple “wiring simulator” in which colored wires are drawn between pins on two connectors. “mc_border” contains the pin diagram drawings for the connectors, I plan to have active hotspots watching for mouse clicks… Is “stacking interactivity” even possible, or should I try a different approach?

Sincere thanks for any suggestions!!

Is the problem your line draws outside of mc_border after the first click? Don’t you want MOVE on mc_border?

The glitchiness of your buttons is probably because you’re creating sprites with graphics that is being drawn under the mouse for your lines. You can probably fix this by setting mouseEnabled = false for each of those sprites.

Thanks for the quick reply! Yes, that was the initial problem…that if I click a color button on the palette first (outside of mc_border) it starts drawing on THAT mouse click, outside the intended drawing area. Basically I want confine all “line-drawing mouse actions” to be within mc_border, allowing other mc’s elsewhere on the stage to retain their own mouse functions.

is that, or is that not fixed by changing stage to mc_border for each of the events?