Copy link to clipboard
Copied
I've been scratching my head on this all morning. I've added rectangles to the stage at runtime via AS 3.0. I drag those rectangles elsewhere on the stage. Now I'd like to use some method to click on one of those rectangles and draw a line to anywhere else on the stage - ideally another rectangle. I thought about using RIGHT_MOUSE_UP and RIGHT_MOUSE_DOWN but those don't seem to work on the Mac using the magic mouse. It's treated as a left click. Anyone have any sample code that might do what I'm looking for?
Thanks!
sure:
var clickNum: int = 0;
stage.addEventListener(MouseEvent.CLICK, clickF);
function clickF(e: MouseEvent): void {
with(this.graphics) {
lineStyle(1, 0xff0000);
if(clickNum % 2 == 0) {
moveTo(this.mouseX, this.mouseY);
} else {
lineTo(this.mouseX, this.mouseY);
}
}
clickNum++
}
Copy link to clipboard
Copied
are you asking about the graphics moveTo and lineTo or asking about right mouse events?
Copy link to clipboard
Copied
LineTo. For example, I move my mouse to a point on the canvas and click. Then I move the mouse to another point on the canvas and click and a line is drawn between the two points I clicked.
OR
Is it possible to dynamically draw a line between two objects on the canvas?
Copy link to clipboard
Copied
sure:
var clickNum: int = 0;
stage.addEventListener(MouseEvent.CLICK, clickF);
function clickF(e: MouseEvent): void {
with(this.graphics) {
lineStyle(1, 0xff0000);
if(clickNum % 2 == 0) {
moveTo(this.mouseX, this.mouseY);
} else {
lineTo(this.mouseX, this.mouseY);
}
}
clickNum++
}
Copy link to clipboard
Copied
Again, thank you so much!!!
I understand what you did exactly. But I doubt I would have come up with it.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now