-
drag & drop question
How do you duplicate an object and start the drag of the duplicated object on the same click? I want to be able to have the duplicated object be able to be dragged as well without it duplicating itself again.
This is for a drag & drop dress-up game. I have gone through a bunch of tutorials but none of them seem to work. I would also like to duplicate the object to the root directory, so If someone wants to close the object menu, then all of the objects that have been dragged onto the model won't dissapear.
Any help you can give me would be great.
-FRIG-5
Das Konzept Design
www.daskonzept.com
-
Style Through Simplicity
So you want somthing to be pressed, it creates a duplicate of that object which is dragable untill you release the mouse?
Put this code on the _root (the mc you press is called mc1 in this code)
Code:
var mcNum = 1;
var dupli:MovieClip;
mc1.onPress = function() {
dupli = mc1.duplicateMovieClip("mcname"+mcNum, ++mcNum);
dupli._x = mc1._x;
dupli._y = mc1._y;
dupli.startDrag();
};
mc1.onRelease = function() {
dupli.stopDrag();
};
mc1.onReleaseOutside = function() {
dupli.stopDrag();
};
Hope that helps. Ask if you dont understand somthing
Ali
Last edited by alillm; 11-29-2005 at 01:25 PM.
-
That helps immensely. Thank You.
I have never seen the dupli:Movieclip syntax before, what does that do or mean?
Would I be able to set up an array of many objects with this, so that anything that is contained in the array, when clicked on, would perform the same function. So that I don't have to repeat the same code for each object.
-FRIG-5
Das Konzept Design
www.daskonzept.com
-
Style Through Simplicity
var dupli:MovieClip; doesnt do anything. It just creates a variable called dupli for use later. The MovieClip bit just tells flash that this variable can only point to a movie clip, so it cant be a number or an array etc.
You could do somthing like this for multiple buttons..
Code:
var obarray = [ob1, ob2, ob3, ob4, ob5];
var mcNum = 1;
var dupli:MovieClip;
for (var i = 0; i<obarray.length; i++) {
obarray[i].onPress = function() {
dupli = this.duplicateMovieClip("mcname"+mcNum, ++mcNum);
dupli._x = this._x;
dupli._y = this._y;
dupli.startDrag();
};
obarray[i].onRelease = function() {
dupli.stopDrag();
};
obarray[i].onReleaseOutside = function() {
dupli.stopDrag();
};
}
Basicly it just loops through all the movie clips in the array and sets up the code for each of them.
Ali
-
ahhh..so that's how you do that. Good to know. Thank you very much.
-FRIG-5
Das Konzept Design
www.daskonzept.com
-
one more question...I was trying to duplicate the movie clip from the menu_mc to to the root folder. I tried changing the depth in the duplicateMovieClip to _root.mcnum+1 or _root.getNextHighestDepth(); BUt this didn't seem to work.
Right now when I close the objects menu - all of the objects that have been dragged onto the stage close with it. If I can duplicate the objects outside of the menu movieClip then that wouldn't happen.
-FRIG-5
Das Konzept Design
www.daskonzept.com
-
Senior Member
the depth is the z orientation. An mc with a high depth will be in front of another mc. Try
_root.duplicateMovieClip(this,"mcname"+mcNum, ++mcNum);
-
sure, but it only controls the depth within that MovieClip, not for the _root directory.
the "this" in the this.duuplicateMovieClip is necessary to point to the object that is being pressed on. Moving the "this" to the parenthesis doesn't work because then you are specifying "this" as the newName of the duplicated movie clip.
-FRIG-5
Das Konzept Design
www.daskonzept.com
-
Senior Member
hmm, you are right. I didn't try it out. My point is that depth is not at all what you are looking for. If you have two movieclips and put them at the same position then the mc with the highest depth will be visible. It is depth in a 3D world without the scaling.
I think you should look into attachMovie instead of duplicateMovieClip.
-
So I am working on integrating attachMovie into the script you had written yesterday. I figured that I needed a new array to go along with the other array that points to the instance names. If put in the same order then I should just be able to call instarray[i] and it would be the instance name for whatever object name was selected in obarray[i]. But this isn't producing any results. I made sure to set the linkage on the clips to "export for actiosncript"
var obarray = [menu.santahat,menu.boombox, menu.carrot, menu.broom];
var instarray = [santa-hat_mc, boom-box, carrot-nose, broom]
var mcNum = 1;
//var dupli:MovieClip;
for (var i = 0; i<obarray.length; i++) {
obarray[i].onPress = function() {
dupli = _root.stage.attachMovieClip(instarray[i],"mcname"+mcNum, ++mcnum);
dupli._x = this._x;
dupli._y = this._y;
dupli.startDrag();
};
obarray[i].onRelease = function() {
dupli.stopDrag();
};
obarray[i].onReleaseOutside = function() {
dupli.stopDrag();
};
}
-FRIG-5
Das Konzept Design
www.daskonzept.com
-
nevermind...I just realized I was using attachMovieClip instead of attachMovie - doh!
-FRIG-5
Das Konzept Design
www.daskonzept.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|