shwoll
04-02-2005, 07:43 PM
Ok so im making a small addition to a program i have to edit pictures and such...well im trying to have a picture loaded in the background and then a rectangle that the user can resize and drag on top of the picture and then i would get those coords and use them for some other stuff... i can draw the rectangle fine...i can resize fine...i can drag fine...but when i drag it does not take the "resize handles" with it...so im messing with different ways of making them stay with the rectangle but im having problems with that...if i have each handle synch with the x y coords of the rectangle....it goes haywire and for however much i move the rectangle...the handles dont go as far and the shape gets all screwed up....if someone could help that would be awesome. thanks!
// place 4 handles on the stage to define our rectangle
//_root.createEmptyMovieClip("photo", 1);
_root.attachMovie("squareHandle", "h1", 5);
_root.attachMovie("squareHandle2", "h2", 6);
_root.attachMovie("squareHandle3", "h3", 7);
_root.attachMovie("squareHandle4", "h4", 8);
handle = 0;
h1._x = 50;
h1._y = 150;
h2._x = 250;
h2._y = 150;
h3._x = 50;
h3._y = 50;
h4._x = 250;
h4._y = 50;
// create an empty clip to put our fill in
// notice that it's level is behind the handles
_root.createEmptyMovieClip("mc", 3);
// this function redraws the fill every time it is called
function draw() {
// clear out the old fill
mc.clear();
// set our fill properties
mc.onPress = function(){
mc.startDrag();
this.onEnterFrame = function() {
h1._x = this._x;
h1._y = this._y + this._height;
h2._x = this._x + this._width;
h2._y = this._y + this._height;
h3._x = this._x;
h3._y = this._y;
};
};
mc.onRelease = function(){
this.onEnterFrame = null;
mc.stopDrag();
};
mc.beginFill(0x0000FF, 20);
// draw the triangle using the handle locations
mc.moveTo(h1._x, h1._y);
mc.lineTo(h2._x, h2._y);
mc.lineTo(h4._x, h4._y);
mc.lineTo(h3._x, h3._y);
mc.lineTo(h1._x, h1._y);
// close the fill
mc.endFill();
}
// this calls the draw function every 25 milliseconds
setInterval(draw, 25);
// that's it. :)
MovieClip.prototype.changeBox = function (){
if(handle == 1){
h4._x = h2._x;
h4._y = h3._y;
h3._x = h1._x;
h3._y = h4._y;
h2._x = h4._x;
h2._y = h1._y;
}else if(handle == 2){
h4._x = h2._x;
h4._y = h3._y;
h3._x = h1._x;
h3._y = h4._y;
h1._x = h3._x;
h1._y = h2._y;
}else if(handle == 3){
h4._x = h2._x;
h4._y = h3._y;
h2._x = h4._x;
h2._y = h1._y;
h1._x = h3._x;
h1._y = h2._y;
}else if(handle == 4){
h3._x = h1._x;
h3._y = h4._y;
h2._x = h4._x;
h2._y = h1._y;
h1._x = h3._x;
h1._y = h2._y;
}
};
// place 4 handles on the stage to define our rectangle
//_root.createEmptyMovieClip("photo", 1);
_root.attachMovie("squareHandle", "h1", 5);
_root.attachMovie("squareHandle2", "h2", 6);
_root.attachMovie("squareHandle3", "h3", 7);
_root.attachMovie("squareHandle4", "h4", 8);
handle = 0;
h1._x = 50;
h1._y = 150;
h2._x = 250;
h2._y = 150;
h3._x = 50;
h3._y = 50;
h4._x = 250;
h4._y = 50;
// create an empty clip to put our fill in
// notice that it's level is behind the handles
_root.createEmptyMovieClip("mc", 3);
// this function redraws the fill every time it is called
function draw() {
// clear out the old fill
mc.clear();
// set our fill properties
mc.onPress = function(){
mc.startDrag();
this.onEnterFrame = function() {
h1._x = this._x;
h1._y = this._y + this._height;
h2._x = this._x + this._width;
h2._y = this._y + this._height;
h3._x = this._x;
h3._y = this._y;
};
};
mc.onRelease = function(){
this.onEnterFrame = null;
mc.stopDrag();
};
mc.beginFill(0x0000FF, 20);
// draw the triangle using the handle locations
mc.moveTo(h1._x, h1._y);
mc.lineTo(h2._x, h2._y);
mc.lineTo(h4._x, h4._y);
mc.lineTo(h3._x, h3._y);
mc.lineTo(h1._x, h1._y);
// close the fill
mc.endFill();
}
// this calls the draw function every 25 milliseconds
setInterval(draw, 25);
// that's it. :)
MovieClip.prototype.changeBox = function (){
if(handle == 1){
h4._x = h2._x;
h4._y = h3._y;
h3._x = h1._x;
h3._y = h4._y;
h2._x = h4._x;
h2._y = h1._y;
}else if(handle == 2){
h4._x = h2._x;
h4._y = h3._y;
h3._x = h1._x;
h3._y = h4._y;
h1._x = h3._x;
h1._y = h2._y;
}else if(handle == 3){
h4._x = h2._x;
h4._y = h3._y;
h2._x = h4._x;
h2._y = h1._y;
h1._x = h3._x;
h1._y = h2._y;
}else if(handle == 4){
h3._x = h1._x;
h3._y = h4._y;
h2._x = h4._x;
h2._y = h1._y;
h1._x = h3._x;
h1._y = h2._y;
}
};