Quantunet.com

My Account

Joins Us

Flash Actionscript QuickSkills
Draggable boxes (Actionscript)  

Download this .fla

//create three empty movie clips on the main time line
//note "this" refers to the root time line
this.createEmptyMovieClip("line",1);
this.createEmptyMovieClip("box1",2);
this.createEmptyMovieClip("box2",3);

// In the movie clip box1 draw a box
// sets the drawing style
box1.lineStyle(1,0x000000);
//sets the fill color
box1.beginFill(0xFF0000);
// explicitly sets the starting point
box1.moveTo(0,0);
//draws the box
box1.lineTo (0,20);
box1.lineTo (20,20);
box1.lineTo (20,0);
box1.lineTo (0,0);
//positions the movie box1 in its stage
box1._x = 100;
box1._y = 200;
//defines what to do on the mouse event
box1.onPress = function () {
this.startDrag ();
}
box1.onRelease = box1.onReleaseOutside = function () {
this.stopDrag ();
}

//creates the second box in the same way as the first
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 ();
}

// draws a line beween the two movie clips box1 and box2
//every time the user moves the mouse over the movieclip the function redraws the line
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);
//updates immediatedly (independently of the frame rate)
updateAfterEvent();
}

 

© 2007 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us