Startdrag + custom function = problems

hi all - after working on this for the better part of today i’ve decided to ask for some assistance!

i have a draggable movieclip (let’s call it the Dragger) that’s loaded into my main movie via a regular mouse event (let’s call it a button named LOAD). it needs to be hidden by default (i have “hidden” and “visible” frame labels inside the Dragger that take care of this). i also need to have another movieclip inside of the Dragger that acts as a closebutton (it will tell the Dragger to hide itself). it has to be inside the Dragger so it will stay in the right position - putting the close button outside of the Dragger isn’t an option. simply attaching a regular mouse event like…

<- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
on(release) {
_root.dragger.gotoAndPlay(“hidden”);
}

                                                                  • >

…to the closebutton doesn’t work… the closebutton doesn’t even seem to know the mouse is being clicked because it’s inside of another movieclip. so i wrote a custom function that goes like this and dropped it onto the first frame of “hidden” and “visible” inside the Dragger (both labels got the code, just to be safe)…

<- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
closebutton.onRelease = function (){
_root.container.goToAndStop(“hidden”);
}

                                                                  • >

…that code magically hides the Dragger like i want and seems to circumvent the problem of the nested MCs. but the problem lies in the fact that the Dragger must be… draggable. so i added the following script onto the Dragger (when it’s on the stage, stopped at the “hidden” label - i put the code on the little tiny crosshair that represents the instance). this makes the Dragger move like i want it to… but kills the closebutton, no matter if i use a custom function to do it or a regular mouse event:

<- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
onClipEvent (load) {
left = _x+1;
top = _y+110;
right = _x+1;
bottom = _y-112;
}

on (press) {
startDrag("", false, left, top, right, bottom);
}

on (release, releaseOutside, rollOut, keyPress “<Escape>”) {
stopDrag();
}

                                                                  • >

so to put it together, i added that code to a MC that’s actually inside the Dragger (after adding “_root.dragger” before start/stopdrag). so i can now drag the Dragger and use the closebutton. but there’s one problem. i click the LOAD button and the Dragger shows up in the right position. but when i click the Dragger to drag it around, it jumps to the upper left corner (0,0) of the stage. it seems like it forgets where its center point is and moves the center point to 0,0. i can sort of play with the top/left/bottom/right etc and get it constrained in one direction, but there’s no way that i can see to position it in the same place.

i think my problem is with the syntax of Actionscript and not knowing how to come up with a hack that forces the Dragger to stay put… or hopefully someone can suggest a more elegant way. ideally i’d like to have the Dragger constrained so that it can only move up and down, not going above or below the edge of the main movie. i will eventually be loading dynamic text and a dynamic JPG into the Dragger, but for now, i just need it to have a closebutton inside that will make the Dragger go to its “hidden” frame label.

i’m attaching a sample FLA (i’d upload my real movie but i’m under a NDA for this project) - i’m betting that someone will be able to just change a few numbers or add a line or two and this thing will be working… thanks in advance…

30 thread views… nobody knows? this is the last thing i have to solve before i can stop working on this project and go outside :frowning:

*Originally posted by iso *
…the closebutton doesn’t work… the closebutton doesn’t even seem to know the mouse is being clicked
goToAndStop should be gotoAndStop.

And for the drag area, check this:
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=27860&highlight=fence+drag+area

thanks for the tip Claudio - i will keep that in mind.

i understand about setting the corner coordinates for making a bounding box - my problem is that the MC jumps to the upper left corner when it’s clicked/pressed for dragging, and then recognizes that it’s bound inside the rectangle. what i want it to do is stay in the position that it shows up in (defined by the blank MC on the stage). it loads into the right place when it’s first called, but once you click it jumps to that upper left corner, no matter how i reposition the blank MC on the stage.

in any case, i almost have it working with:

<----------
on (press) {
_root.loader.startDrag(0, 485, 300, 485);
}

on (release, releaseOutside, rollOut) {
_root.loader.stopDrag();
}
----------->

but i want to use “false” to prevent the Dragger from jumping to center itself on the mouse position. unfortunately adding “false” makes the Dragger start jumping back to that upper left side. argh…

so why does it jump out of the original location of the blank MC?

Probably because the initial positin of the object to be dragged is ourtside the draggable area. I havent looked the code, im a little busy now. I made a litle example for you. Gotta go now…

ahhh, i see - thanks to your comment (and your new file) i realized that the Dragger stays in place because the black crosshair that’s inside the movie clip is inside the draggable area, as Claudio specified… when i align the Dragger’s upper left corner with the crosshair, it does the right thing. thanks, you’re awesome!

just for future reference, does anyone know a way to move the crosshair through some palette or menu, or will i have to drag my movie around each time i want to do something like this? it’s sort of inconvenient when the crosshair is in the middle of the movie and the MC i want to edit is wider than half the main movie’s width…

thanks again!

You can align the object using the Align Panel. Just hit Ctrl+K to bring it on stage.

yes, but it also aligns all the little objects inside my MC… so i did it manually. i guess there’s no way to manually position the crosshair…

just want to say thanks again, Claudio - i worked on this for way too long!

You’re welcome :slight_smile:
Just group both objects usign Ctrl+G then align them on stage.
:wink: