I'm looking into having a interface using multiple windows which you can drag by pulling the dragbar around.
Each window would be a movieclip called *****_win and inside would be a dragBar that the mouse has to pull around to move the window.
I have searched a lot on google, and decided to end up asking here.
1) All the code I used so far did not have any borders. (The borders would be the stage, not an image).
2) Whenever I dragged an object, it would drag the whole window.
3) If the cursor left the window while dragging (which is does a lot), I have to drag it again.
Anyway how I can do an OS-like way of dragging a window?
Last edited by Anthonie Goes; 09-24-2009 at 02:00 PM.
Well I'm going to take a stab at what your going for here.
You want to do a drag and drop, and you want to use numerous movieclips but want minimal code. Is this correct? If so, try this:
name all your movieclips with this at the beginning of the name "dmc_", and use a number after the underscore: I.E. - dmc_1, dmc_2, dmc_3 Then use this code:
Code:
for (var i:uint = 1; typeof(this["dmc_"+i]) != "undefined"; i++) {
this["dmc_"+i].addEventListener(MouseEvent.MOUSE_DOWN, startD);
this["dmc_"+i].addEventListener(MouseEvent.MOUSE_UP, stopD);
}
function startD(evt:MouseEvent):void {
evt.currentTarget.startDrag(false);
this.setChildIndex(MovieClip(evt.currentTarget), numChildren - 1);
}
function stopD(evt:MouseEvent):void {
evt.currentTarget.stopDrag();
}
Every movieclip inside has a movieclip called dragBar. (Which could be dragBar_1 or dragBar_2 corresponding to the number of the movieclip.)
Kind of like an operating system, I only want the object to be dragged by that 'bar'.
Also, how would I go around making the stage's borders into dragging borders? I tried stage.height and stage.width, and it worked for the left and top border, but the bottom and right border were just open.
I injected the code, made a movieclip called dmc_2, put a little bar on the top of dmc_2 called aClip, set their instance names to the same, and tested the movie.
I have one trouble though, how would differently sized 'aClip's do? I have 'windows' of various sizes, like a small one, and a very big one. Every window needs to have the correctly sized aClip, perhaps I should use the frame inside aClip? How would the code look for that?
You can make the aClip any size you want as long as it's the same size or smaller than it's parent clip, the code I gave bases the borders and such from the parent clip dimensions.
The code would be the exact same, you'd just have different sized aClips.
If you'd like, you can email me a source file at jonathon.weeks@gmail.com, and I'll do whatever I can to help.
Your problem lies in the orientation of dmc_2 you have it's movieclip orientation set to the center, this code is made for it to work with the orientation set to the top right. Know what I mean?
How do I adjust the code so it brings the movieclip to the top if the whole movieclip is clicked? Now I can bring a movieclip to top when I start dragging or click the dragbar, but I want it to go to the top when aClip is clicked.
Thanks, and sorry for reviving this resolved thread.