Hi all:
I need to be able to draw 2 boxes connected with a line when the user clicks on the stage. I also need to be able to drag and reposition any of the boxes.
I got the code below from a sample, which partially works for my need. I added a background MC named mycanvas because I couldn’t get the boxes to draw when I click on the stage of the movie.
What code can I use to do the following:
- Add the 2 boxes and line at the point the mouse is clicked on the stage
- Be able to add multiple 2 boxes each time the stage is clicked.
- Be able to move each individual box to a new position.
Thanks. Here is my current code:
mycanvas.onPress = function() {
mycanvas._root.createEmptyMovieClip(“line”, 1);
mycanvas._root.createEmptyMovieClip(“box1”, 2);
mycanvas._root.createEmptyMovieClip(“box2”, 3);
mycanvas._root.box1.lineStyle(1, 0x000000);
mycanvas._root.box1.beginFill(0xFF0000);
mycanvas._root.box1.moveTo(0, 0);
mycanvas._root.box1.lineTo(0, 20);
mycanvas._root.box1.lineTo(20, 20);
mycanvas._root.box1.lineTo(20, 0);
mycanvas._root.box1.lineTo(0, 0);
mycanvas._root.box1._x = 100;
mycanvas._root.box1._y = 200;
mycanvas._root.box1.onPress = function() {
this.startDrag();
};
mycanvas._root.box1.onRelease = mycanvas._root.box1.onReleaseOutside=function () {
this.stopDrag();
};
box2.lineStyle(1, 0x000000);
box2.beginFill(0x0099FF);
box2.moveTo(0, 0);
box2.lineTo(0, 20);
box2.lineTo(20, 20);
box2.lineTo(20, 0);
box2.lineTo(0, 0);
box2._x = 400;
box2._y = 200;
box2.onPress = function() {
this.startDrag();
};
box2.onRelease = box2.onReleaseOutside=function () {
this.stopDrag();
};
this.onMouseMove = function() {
line.clear();
line.lineStyle(1, 0x000000);
line.moveTo(box1._x+10, box1._y+10);
line.lineTo(box2._x+10, box2._y+10);
updateAfterEvent();
};
};