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!!