Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Drag And Drop To Any Drop Target



Hi guys....I am trying to create some more generic code for a project im on....infact you guys have already helped me lots in getting it up and running! I have basicly got it where all the dragObjects and assigned functions within a for loop and therefore been assigned to their own dropTargets...all working fine, however a situation is needed where if a user drops a clip onto anything rather than a hit area it doesnt just register as an incorrect drop.....at the moment a drag that misses a dropTarget will be the same as one that is dropped onto an incorrect drop target and thats just a bit unfair for them as it means they have used up one of only two chances!!! basicly I need to know if its possible to obtain using the coding style that i already have been whether a drop is onto any of the drop targets before than going to chec if its the correct one or not....sorry for the long winded talk but seemed the only way i could explain!!! the code i'm using is below
Code:
var Xpos:Number;var Ypos:Number;var objects:Number = 2;for (i = 1; i <= objects; i++) { // assigning the on press events to the dragObjects this["dragObject"+i+"_mc"].onPress = function() { this.startDrag(true); // assigning the original X and Y of the dragged clips Xpos = this._x; Ypos = this._y; } // assinging the on release events to the dragObjects this["dragObject"+i+"_mc"].onRelease = function() { // finding the number of the dragObject to use in the submitAnswer function objName = this._name dragNumber = Number(objName.substr(10, 1)); submitAnswer(dragNumber); } }// function to assertain whether the drop was a successful one - whether dropObecjt1 was dragged on dropTarget1 and so on // the number is passed from the onRealease functionfunction submitAnswer(dragNumber:Number) { this.stopDrag(); // if its dropped onto its correct target then turn the button off, place ontop of its target if (this["dragObject"+dragNumber+"_mc"].hitTest(this["dragTarget"+dragNumber+"_mc"])) { this["dragObject"+dragNumber+"_mc"].enabled = false; this["dragObject"+dragNumber+"_mc"]._x = this["dragTarget"+dragNumber+"_mc"]._x+50; this["dragObject"+dragNumber+"_mc"]._y = this["dragTarget"+dragNumber+"_mc"]._y+50; trace ("knob jockey"); } else { // if it is dropped onto a wrong target then chuck it back to where it started! this["dragObject"+dragNumber+"_mc"]._x = Xpos; this["dragObject"+dragNumber+"_mc"]._y = Ypos; }}
thanks for any help!!



KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 06-17-2004, 11:32 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Drag&Drop Duplicate Movie With Drop Target
Hi There...

I'm creating a game where people can design their own cell phone by adding diamonds to it, a "Bling Phone" if you will. You will be able to add 4 types of diamonds to it, change the phones skin, add music to it, give it a name etc etc

I've got it to a stage where it when you click on a diamond(mc) on the stage it duplicates a hidden diamond(mc with a button inside) off stage and you can drag it around etc and then click save. Theres a script which grabs the instance name, x and y position of every diamond on the stage and stores it into a multi dimensional array which will be fed into a mysql database for retreival purposes at a later date.

Now my problem is i would like to be able to use the phone(mc) as a drop target but i'm not sure where to put the droptarget script. does it go on the original MC diamond or the duplicated mc diamond with the button inside it ?

Once a diamond has been dropped onto the phone i would also like it if the user then drags the diamond off the phone it gets deleted. I think i've got it half working but my variables which keep track how many diamonds are on stage dont appear to be updating.

I've attached the .fla file to this post if some is interested in taking a look and helping me out. The droptarget script is only on the blue diamond so far.

Any help would be much appreciated.

Thanks

Rob

Drag And Drop - Multiple MC's On To A Single Drop Target
Hi All

I am struggling with a drag and drop excercise.

I have 15 movie clips that need to be dragged over a single drop target in a specific order. i.e 1,2,3,4, when the correct movie clip is dragged to the drop target a movie within the drop target needs to advance a single frame to display the result of the correct movie clip being dragged over the drop target.

Would I be correct in thinking I need to use some kind of array to compare the clip that is being dragged to the frame position of the drop target?

I have the bones of this working and need advice / help on getting the clips to work in the specific order required. I can post my code if needed.

Thanks in advance.

btw - am using Flash MX 2004 Professional

Drag Abd Drop, Rollover When Drag Is Over Drop Target?
Hi, im using Flash MX 2004.

I am building a drag and drop, and I have a MC that can be dragged around the stage. The trouble im having is trying to make the drop location do something when i drag the MC over/off it.

I have the following code which works.

objectToDrag.onMouseMove = function() {
if ((objectToDrag.hitTest(dropper)) && (component._beingDragged == true)) {
dropper._alpha = 50;
temp++;
trace("working"+temp);
}
}

This will make the clip i am dragging the draggable MC over change alpha, but for the life of me I cant figure out how to get the alpha to change BACK, after the draggable MC is taken away from the 'dropper'.

Is there a better way that hitTest??

Cheerz,
Dwayne

Drag And Drop To Any Drop Target
Hi guys....I am trying to create some more generic code for a project im on....infact you guys have already helped me lots in getting it up and running!

I have basicly got it where all the dragObjects and assigned functions within a for loop and therefore been assigned to their own dropTargets...all working fine, however a situation is needed where if a user drops a clip onto anything rather than a hit area it doesnt just register as an incorrect drop.....at the moment a drag that misses a dropTarget will be the same as one that is dropped onto an incorrect drop target and thats just a bit unfair for them as it means they have used up one of only two chances!!!

basicly I need to know if its possible to obtain using the coding style that i already have been whether a drop is onto any of the drop targets before than going to chec if its the correct one or not....sorry for the long winded talk but seemed the only way i could explain!!!

the code i'm using is below


Code:


var Xpos:Number;
var Ypos:Number;
var objects:Number = 2;
for (i = 1; i <= objects; i++) {

// assigning the on press events to the dragObjects
this["dragObject"+i+"_mc"].onPress = function() {
this.startDrag(true);
// assigning the original X and Y of the dragged clips
Xpos = this._x;
Ypos = this._y;
}

// assinging the on release events to the dragObjects
this["dragObject"+i+"_mc"].onRelease = function() {
// finding the number of the dragObject to use in the submitAnswer function
objName = this._name
dragNumber = Number(objName.substr(10, 1));
submitAnswer(dragNumber);

}

}
// function to assertain whether the drop was a successful one - whether dropObecjt1 was dragged on dropTarget1 and so on
// the number is passed from the onRealease function
function submitAnswer(dragNumber:Number) {
this.stopDrag();
// if its dropped onto its correct target then turn the button off, place ontop of its target
if (this["dragObject"+dragNumber+"_mc"].hitTest(this["dragTarget"+dragNumber+"_mc"])) {
this["dragObject"+dragNumber+"_mc"].enabled = false;
this["dragObject"+dragNumber+"_mc"]._x = this["dragTarget"+dragNumber+"_mc"]._x+50;
this["dragObject"+dragNumber+"_mc"]._y = this["dragTarget"+dragNumber+"_mc"]._y+50;
trace ("knob jockey");
} else {
// if it is dropped onto a wrong target then chuck it back to where it started!
this["dragObject"+dragNumber+"_mc"]._x = Xpos;
this["dragObject"+dragNumber+"_mc"]._y = Ypos;
}
}
thanks for any help!!

Drop Target In "drag And Drop Game"
Im very much confused that how the code is wrong here..?on (press)
{
startDrag (this, false);
}
on (release)
{
stopDrag ();
if (_droptarget eq _root.cpu)
{
_root.score = int(_root.score + 1);

gotoAndStop(2);
}
else
{
_root.score = int(_root.score - 1);
gotoAndStop(2);
answer.gotoAndPlay("wrong");
} // end else if
}

Here im prepairing a game where i had palce this script inside a movie clip,having two option Correct amd Wrong,
I had created a box name keyboard
where an image of keyboard when placed it should show that its correct,and..if the movie clip calledkeyboardbutton is placed outside then it shoul show its wrong.
keyboardbutton is the instance name for that keyboard,
Actually its a game showing the Process of flow of operation in Computer..
Where i had also used the CPU and Monitor..please anyone help me out here...
here is a sample file for that:

Drag N Drop Target
Think of this question as a menu. Say I have like 7 draggable MCs, but I only have 1 target to drop these MCs into. When I drop these MCs into the target, I want it to recognize which MC is being dropped there. I can make the drag n drop just fine, I just don't know how to make the target realize which MC is on it.

Riki

Drag/drop/target - Help
I have spent the past few days hunting for a tuturial that would walk me step by step through creating a drop and drag interaction.

I have mastered drop. I have mastered drag.

I am unable to master creating the target to evaluate if it is correct or not and then resetting or providing feedback.

Any help would be appreciated !!!

Drag And Drop To Target
Could someone remind me:
I want the user to be able to drag and drop a movie clip onto another movie clip (no problem), however, if they place the first movie clip onto the wrong mc I want to prompt them to try again. If it is correct I simply want the first mc clip to stay in the correct placement and congratulate them with another "popup". I have done this before, but it has eluded me this time. Thanks a bunch.

Drag And Drop To Target
This should be easy for you pros.

How do I make a draggable ball when dropped onto a target, tell the movie to go to the next frame.

If the ball is not dropped on the correct target, I need it to return to it's original position.

Thanks,

TNBANJOMAN

Drag And Drop Is Not Quite On Target
I've created a movie clip with
1) a button inside (IPbutton)
2) a target named IP_place
3) a feedback movie clip named "feedback"

The button has the following script and when I test the movie, the button drags and drops, but "feedback" doesn't play. Any ideas on what the problem is? Do I need to specify exact coordinates for the target - and if so, how?
Thanks!

on (press) {
startDrag(IPbutton);}
on (release) {
stopDrag(); {
if (_droptarget = IP_place) {
with (feedback) gotoAndPlay(2);
}}}

[F8] Drag And Drop To Target
heya all.

hope you can help me here please.

i followed this lovely tutorial here: http://www.flashkit.com/tutorials/In...r-25/index.php

to create a jigsaw piece that when draged sits on it's appropriate target. however i have noticed that you don't have to drop it specifically on target - just touching it somewhere and the piece then becomes unmoveable. i would like to get it to sit precisely on it's target (which i will make invisible) so that all the pices can sit neatly togeter. how would i go about this?

all help recieved with gratitude.

kerry

Drag And Drop To A Target
I can do the start drag and stop drag, but how do I make sure it will align into a target area? Hit the target, so to speak.

thanks in advance

Drag & Drop On Target
Hello!
I have a problem.
I want to drag a few different numbers to a few different targetshapes. This is the code I have now:


Code:
var counter:Number = 0;
var startX:Number;
var startY:Number;

siffra_6.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
siffra_6.addEventListener(MouseEvent.MOUSE_UP, dropIt);
siffra_32.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
siffra_32.addEventListener(MouseEvent.MOUSE_UP, dropIt);
siffra_21.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
siffra_21.addEventListener(MouseEvent.MOUSE_UP, dropIt);
siffra_11.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
siffra_11.addEventListener(MouseEvent.MOUSE_UP, dropIt);
siffra_18.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
siffra_18.addEventListener(MouseEvent.MOUSE_UP, dropIt);

function pickUp(event:MouseEvent):void {
event.target.startDrag(true);
reply_txt.text = "";
event.target.parent.addChild(event.target);
startX = event.target.x;
startY = event.target.y;
}

function dropIt(event:MouseEvent):void {
event.target.stopDrag();
var myTargetName:String = "target" + event.target.name;
var myTarget:DisplayObject = getChildByName(myTargetName);

if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){
reply_txt.text = "Good Job!";

event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
event.target.buttonMode = false;
event.target.x = myTarget.x;
event.target.y = myTarget.y;
counter++;
} else {
reply_txt.text = "Try Again!";
event.target.x = startX;
event.target.y = startY;
}
if(counter == 4){
reply_txt.text = "Bra jobbat!";
gotoAndPlay(4);
}
}

siffra_6.buttonMode = true;
siffra_32.buttonMode = true;
siffra_21.buttonMode = true;
siffra_11.buttonMode = true;
siffra_18.buttonMode = true;
What this code does is enable the movie clips siffra_6, siffra_32... to be draged onto the targetshapes that has the correct name, and get stuck there, if the movie clips are droped somewhere else, they jump back to their original position. What I want to change is the following:
I want the movie clips siffra_6, siffra_32... to get stuck even if they are dropped on the wrong targetshape. How could that be done?
I would also like to add another function to this.
After all movie clips have been dropped I would like them to change color depending on if they are on the correct position or not.

Drag And Drop To Same Target
Can someone point me in the right direction please, ive used the code from a tutorial to drag and drop movies onto separate targets, but now want to drag movies onto the same target, and if one movie is on the target send it back to its origin.

the code from the tutorial is from monkeyflash.com

var counter:Number = 0;
var startX:Number;
var startY:Number;

square_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
square_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
triangle_mc.addEventListener(MouseEvent.MOUSE_DOWN , pickUp);
triangle_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
flower_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
flower_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
pentagon_mc.addEventListener(MouseEvent.MOUSE_DOWN , pickUp);
pentagon_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);

function pickUp(event:MouseEvent):void {
event.target.startDrag(true);
reply_txt.text = "";
event.target.parent.addChild(event.target);
startX = event.target.x;
startY = event.target.y;
}
function dropIt(event:MouseEvent):void {
event.target.stopDrag();
var myTargetName:String = "target" + event.target.name;
var myTargetisplayObject = getChildByName(myTargetName);
if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){
reply_txt.text = "Good Job!";
event.target.removeEventListener(MouseEvent.MOUSE_ DOWN, pickUp);
event.target.removeEventListener(MouseEvent.MOUSE_ UP, dropIt);
event.target.buttonMode = false;
event.target.x = myTarget.x;
event.target.y = myTarget.y;
counter++;
} else {
reply_txt.text = "Try Again!";
event.target.x = startX;
event.target.y = startY;
}
if(counter == 4){
reply_txt.text = "Congrats, you're finished!";
}
}

square_mc.buttonMode = true;
flower_mc.buttonMode = true;
triangle_mc.buttonMode = true;
pentagon_mc.buttonMode = true

I have this working with 6 movies to ten targets, there must be an esier way to do this than putting all ten targets on top of each other

thanks

Andy

Drag'n'drop And Target Somewhere Else
here's the problem. i need to load a movie clip into a controlling movie. it's loaded into a holding movie clip so it can be moved. once in there, i need to drag an enclosed mc out and drop it onto the _root (not within the holding mc) so that it will stay where it is when the loaded mc is unloaded. does that make any sense?

i've tried the attachMovie and link library method, but this would be no good as loaded mc's will need to be dynamically created and made available in the controller without actively changing the controller.

there must be a way to do this in flash. anybody know?

ralpho

Drag & Drop Target
my drag and drop target works...sort of. Here's the problem, when the target is dropped it should tell the user if it is correct. It does but you have ot keep drag and dropping all over the target to finally get the answer to display. I have checked the registation marks and stage alignment...nothing seems to work. it should be if you drop it over the hit (instance name) it should immediately display the answer of "correct"

Here is the code for the drop target:

on (press) {
startDrag(this, true);
}
on (release) {
stopDrag();
if (this._droptarget == "/cat_a") {
_root.cat_a.gotoAndPlay(2);
}
}

this is the hit target:

2 frames...first says:
stop();

if (this._droptarget == "/cat_a") {
_root.cat_a.gotoAndPlay(2);
}

Second frame is the answer "correct"

there is also a second line with a stop action in the second frame

Any help would really be appreciated.

Drag Drop Target
Hello,

i'm kinda new to flash and i need some help. I'm trying to make a drag drop puzzle like this one. I can do the drag and drop bit, but does anybody know how you make a target in witch the picture can fit exact?

http://www.funzac.com/play/Photo%20Puzzle.html

For example, when you drag the picture over the area where you want to put it, but it isnt an exact fit, the puzzle itself makes it an exact fit.. If you dont know what i mean you can follow the link and than drag and drop a bit..

Thanks!

Drag & Drop Target
my drag and drop target works...sort of. Here's the problem, when the target is dropped it should tell the user if it is correct. It does but you have ot keep drag and dropping all over the target to finally get the answer to display. I have checked the registation marks and stage alignment...nothing seems to work. it should be if you drop it over the hit (instance name) it should immediately display the answer of "correct"

Here is the code for the drop target:

on (press) {
startDrag(this, true);
}
on (release) {
stopDrag();
if (this._droptarget == "/cat_a") {
_root.cat_a.gotoAndPlay(2);
}
}

this is the hit target:

2 frames...first says:
stop();

if (this._droptarget == "/cat_a") {
_root.cat_a.gotoAndPlay(2);
}

Second frame is the answer "correct"

there is also a second line with a stop action in the second frame

Any help would really be appreciated.

Drag And Drop Target
Hi,

I have drag and drop target question:
What is the main reasons that two movie clips doesn't equal when getProperty(my_mc, _droptarget)?

Plai-or
http://www.quality-web-design.netfirms.com

Drag + Drop Target.. What Am I Doing Wrong?
it just doesn't work? i've been over and over it..

i have a littlebox and a bigbox - i just want to have the bigbox play when the littlebox is dropped onto it.. i cannot even drag the littlebox at the moment though..

here is the code i put on the little box button

on (press) {
startDrag ("_root.littleBox");
}
on (release) {
stopDrag ();
if (_root.littleBox._droptarget == "/bigBox") {
_root.bigBox.gotoAndPlay("move");
}
}

the bigBox is the movieclip (target) and yes it's called bigBox
the littleBox is the button inside the movieclip called "little" and yep the button is called "littleBox" ... seriously i cannot figure out what is missing here. ?
i followed the tutorial exactly..

and i'f anyone would like to take a look at the file i'll mail it to you.
(( i'm using flash 5 and running it on an imac ))

Drag And Drop W/ Fixed Target
Hi,

I ran into some problems with the drag and drop function.

Attached is the fla. Please advice.

I created a button (embedded in 1 action script) with 4 different targets...the score on the scene would be populated based on the different value.

2 on the main scene
while 2 embedded in a movieclip.

The 2 on the scene are functioning correctly.. but not the ones in the movieclip.

this is the code my button is attached to
on (press) {
startDrag("/clip1");
}

on (release) {
stopDrag ();
if (_droptarget eq "_root.plan.target1") {
_root.score = 1;
}
if (_droptarget eq "_root.plan.target2") {
_root.score = 3;
}
if (_droptarget eq "/target3") {
_root.score = 2;
}
if (_droptarget eq "/target4") {
_root.score = 5;
}
}

Hmm.. what is the mistake on my target for target1 and target2?

PS: plan = name of mc
score <-- score tracker.

Please advise.

thanks

Drag And Drop Snap To Target
Hi
Could someone please help me with the code required to make a drag object snap onto a target(s) when in close proximity?
Many thanks

Drag And Drop Hit Target Highlight
I need help creating a drag and drop, that would have drop indicator that would let you
know where you are dropping your movieClip BEFORE you actually drop it.
This would be like in www.start.com
when you start to drag a portlet (e.g. the Weather Forecast portlet), you get a red dotted box to let you know, this is where
it's going to land when you let go of the mouse.

I have accomplished the drag and drop, but I can't seem to figure out how to create the
highlited target area to let you know, this is where your item will land when you release the mouse.
The animation in www.start.com is not necessary. I just interested in the red box highlight funtionality.

thanks
tg

Drag And Drop : Target Prob
hi
ok i have 100 movie clips on the stage cause its a board. and i have a one mc to drag and drop on the board but i dunno what target to write. usually target script looks like this :

if(this._droptarget == "/mcTarget")
this.stopDrag();

but my mcTargets are mc named tile1 - tile 100.
i dont think that i have to make everey if for 100 mc.
cheers

[F8] Drag And Drop With Target Areas
I had a go at the "Drag and Drop with Target Areas" tutorial by Peter Brouwers, and downloaded the example. I created a new one and used the example to create my own. I did what the example showed me (created four movie clips, two squares at the top, two circles at the bottom, and included the button only in the first circle, then applied some actionscript to both the frame and button).
All that was changed between the two was the instance names.

When I run my movie, the button does not drag like it should, even though the actionscript for it is the same as Peter's. I cannot understand what the difference is. If I can figure it out, then I will create a button for the second circle and create a button in it, then repeat the actionscript.

Drag And Drop Hit Target With Highlight
I need help creating a drag and drop, that would have drop indicator that would let you
know where you are dropping your movieClip BEFORE you actually drop it.
This would be like in www.start.com
when you start to drag a portlet (e.g. the Weather Forecast portlet), you get a red dotted box to let you know, this is where
it's going to land when you let go of the mouse.

I have accomplished the drag and drop, but I can't seem to figure out how to create the
highlited target area to let you know, this is where your item will land when you release the mouse.
The animation in www.start.com is not necessary. I just interested in the red box highlight funtionality.

thanks
tg

Drag And Drop Target In An Imported SWF
Hi All,
I am in a bit of a bind here, I am doing a finals for my Flash class in college and our assignment is to make a portfolio that show cases our past work, well I had made an easter egg hunt SWF where object is to find eggs and drop them into a bucket, main use of action script is the drag and drop target, By itself the SWF runs just fine but when I try to import that swf by method LoadMovie ( I am loading all my shows externally) my drag and drop target breaks. I can drag the egg over to the bucket but it dont "drop" the intial code for the drag and drop is this
code -->
on (press) {
startDrag("");
}
on(release) {

stopDrag();
if (eval(this._droptarget) == _root.EasterBasket) {
setProperty(this, _visible, false)
_root.count --;
tSound = new Sound(this);
tSound.attachSound("thump");
tSound.start(0,0);
}
}
<-- end code
I have tried using the lockroot command to keep the timelines seperate but that didnt help, I changed the _root.EasterBasket to this._parent.EasterBasket to get rid of root reference but that didnt work either. is there a better mousetrap out there that I can use for this drop and drag target that will work when it is imported to another SWF, I need help fast please, this project is due here pretty quick, thanks all, D-Wiz

Mx 2004 Drag And Drop With Target
Hi all I've been looking for a tutorial on how to create drag and drop with a defined target areas. I have seen some code over on another forum but the instructions are far from helpful really, I wondered if anyone could shed some light on where I fail to understand.

The forum link is http://www.flashkit.com/tutorials/In...r-25/index.php

I like this idea because if it isn't correct then it snaps back to original position and if correctly matched up then the object stays put.

The flash application seems simple enough but the explanation seems to fall short.

The instructions say that for the object which is 'draggable', first you should create a movie clip and then you should create button and insert this within the first keyframe of the movie clip.So ok I can create a shape and convert to movie clip but no matter what I do, I'm unable to add a button into keyframe 1 of that movie clip itself?

I have got a button thats exactly the same as the shape and have double left clicked the movie clip itself to make it selectable but when I then try to import my button from the library is always says 'cannot perform this action on an object.

I've been trying various things for 30-45 mins with no avail.

Can anyone tell me please where I'm going wrong? I did notice a drag / drop on http://www.kirupa.com/developer/acti...t/dragdrop.htm but it only applies for 2 shapes dragged over the one item.

Are there any suggestions please?

thanks in advance,
Michael

Drag And Drop Object Onto Target And Back Again
please help!
I want to be able to drag and drop an object onto a target area. If it doesn't go over target area I want it to go back to its start position.
When droped on the target area I want it to be dragable. When dragged outside the target area I want it to snap back to the origional start position.
Have had a look at Peter Brouwers tutorial on this site and so far so good except that when I drag the object out of the target area it goes to the previous position as oposed to the start position, am new to this actionscript thing and any help would be appreciated.
thanks...

Drag And Drop Target Load Movie
Im try to figure out how i would go about a certain drag and drop ,with a traget. what i want is when a user drags an icon to a specific spot on the site and release's the mouse this wil load the swf with that file in it.. if anybody would happen to know how i would do this that would be great..

Drag, Drop, Target, Play, Return
I am looking for a tutorial or the like on how to drag and drop a mc into another mc. Once this mc is drop I want it to start playing. I want to use this option to load the different sections of my site. Once a new section is chosen I also need the original selection to go back to its beginning state. Any help would be greatly appreciated. An example of what I want to do can be seen here.
http://www.trollback.com/ Thanks in advance for any help that can be offered.

Keith

Query About Drag And Drop With Target Areas
I sent an email to Peter Brouwers (p.brouwers@kw1c.nl) but it came back underliverable so I am wondering if any one else can assist me with this?

I used his tutorial on Flashkit http://www.flashkit.com/tutorials/In...r-25/index.php to create 6 draggable objects with corresponding target areas and it worked well except for the fact that I wish to allow for the user dragging the objects to their places in any order they wish as long as ultimately they are all put in the correct positions.

What code do I need to use to check if all the objects are in their correct target positions and only then the feedback sound will play. (for example if object 6 is dragged to its correct location the feedback sound will only play if the other 5 objects are also in the correct locations.)

Thanks a mil!

Newtoo

Question On Two Target Drag And Drop Files.
Hi guys, great site you have here.

Anyways here is my problem where I am stuck.

I'm making a flash project for class and I have a simple drag ang drop snapping file on a target. (a blue ball that snaps to a red square and if you miss the red square returns to it's origin)


Here is the code I have right now.



on (press) {
this.startDrag(true);
}
on (release) {
this.stopDrag();

if (this.hitTest(_root.chris)){

_root.gotoAndStop;{this._x = 401;
this._y = 127;}
} else {

this._x = 81;
this._y = 327;
}
}


Now this code works perfect. My question is how do I add another target to the script. So if I have two targets I can drag the object to one or the other.

My second target is chris2 and I need to get it to be in x = 201 and y = 127

Any help would be great!

Thanks!!!

Drag And Drop Target On Imported SWFs
Hi All,
I am in a bit of a bind here, I am doing a finals for my Flash class in college and our assignment is to make a portfolio that show cases our past work, well I had made an easter egg hunt SWF where object is to find eggs and drop them into a bucket, main use of action script is the drag and drop target, By itself the SWF runs just fine but when I try to import that swf by method LoadMovie ( I am loading all my shows externally) my drag and drop target breaks. I can drag the egg over to the bucket but it dont "drop" the intial code for the drag and drop is this
code -->
on (press) {
startDrag("");
}
on(release) {

stopDrag();
if (eval(this._droptarget) == _root.EasterBasket) {
setProperty(this, _visible, false)
_root.count --;
tSound = new Sound(this);
tSound.attachSound("thump");
tSound.start(0,0);
}
}
<-- end code
I have tried using the lockroot command to keep the timelines seperate but that didnt help, I changed the _root.EasterBasket to this._parent.EasterBasket to get rid of root reference but that didnt work either. is there a better mousetrap out there that I can use for this drop and drag target that will work when it is imported to another SWF, I need help fast please, this project is due here pretty quick, thanks all, D-Wiz

Drag And Drop Based On Proximity To Target, Can It Be Done?
I wonder if someone can help me with a Drag and Drop problem.
I am using Flash 8.

I have used this drag n drop tutorial, http://www.flashkit.com/tutorials/In...r-25/index.php


The Problem:

I want the drag object to snap to its target based on adjustable proximity to the target. The reason for this is that my target and drag icons are small on a small cluttered stage representing a detailed map, so i would like to experiment with adjustments before commiting to a final range figure. So instead of the drag needing to be dead centre to the target, it could for example be within 50% of the centre, but still snap to the target on mouse releases.

what code would i need to insert for each drag icon?

Here is my code for the drag mc.

on (press) {
startDrag(getProperty(_x, _y));
}
on (release) {
stopDrag();
if (_droptarget eq "/TA1") {
nextFrame();
} else {
setProperty("", _y, OrgY);
setProperty("", _x, OrgX);
}
}

Drag And Drop Target On Imported Movies
Hi All,
I am in a bit of a bind here, I am doing a finals for my Flash class in college and our assignment is to make a portfolio that show cases our past work, well I had made an easter egg hunt SWF where object is to find eggs and drop them into a bucket, main use of action script is the drag and drop target, By itself the SWF runs just fine but when I try to import that swf by method LoadMovie ( I am loading all my shows externally) my drag and drop target breaks. I can drag the egg over to the bucket but it dont "drop" the intial code for the drag and drop is this
code -->
on (press) {
startDrag("");
}
on(release) {

stopDrag();
if (eval(this._droptarget) == _root.EasterBasket) {
setProperty(this, _visible, false)
_root.count --;
tSound = new Sound(this);
tSound.attachSound("thump");
tSound.start(0,0);
}
}
<-- end code
I have tried using the lockroot command to keep the timelines seperate but that didnt help, I changed the _root.EasterBasket to this._parent.EasterBasket to get rid of root reference but that didnt work either. is there a better mousetrap out there that I can use for this drop and drag target that will work when it is imported to another SWF, I need help fast please, this project is due here pretty quick, thanks all, D-Wiz

Drag And Drop Target Stuck To Mouse - Help- See Swf.
Hi, i´ve been going through some tutorials and samples of "drag and drop" flash movies and I always come apon the same bug. The drop target gets "stuck" to the mouse, and when I click the target it just drops down and doesn´t return to its orig. position. This mostly happens when the target in the "lower order" is droped behind a target that is "in front of it" Now I have used the


Code:
this.swapDepths(_root.getNextHighestDepth());
to fix the "order" problem but still the problem some times happens. - You can see the problem in the fla/swf if you drag on of the "lower order targets" under the "front targets".

Does any one know if there is a way to fix this...?

Drag And Drop Based On Proximity To Target, Can It Be Done?
Hello All, (please be gentle with me, actionscript is very new to me...)

I wonder if someone can help me with a Drag and Drop problem.

I want the drag object to snap to its target based on adjustable proximity to the target. The reason for this is that my target and drag icons are small on a small cluttered stage representing a detailed map, so i would like to experiment with adjustments before commiting to a final range figure. So instead of the drag needing to be dead centre to the target, it could for example be within 50% of the centre, but will still snap to the target when the mouse is released. The target locations will be changed for each map, and will mean that I will not have exact x,y coordinates.

what code would i need to insert for each drag icon?

Here is my code for the drag mc.

on (press) {
startDrag(getProperty(_x, _y));
}
on (release) {
stopDrag();
if (_droptarget eq "/TA1") {
nextFrame();
} else {
setProperty("", _y, OrgY);
setProperty("", _x, OrgX);
}
}

Drag & Drop Multiple Objects To 1 Target..how?
Hi there

I am just starting with AS3 and therefore please be gentle with me. I am trying to create a drag and drop learning exercise and have been using This tutorial as my base. All is fine for having 1 object dragged to 1 target but i really need to have several different objects dragged to just 1 target and i can't figure out how to do this

Any help would be greatly appreciated as i am going to need to do this a lot in the future.

cheers.

Drag - Drop Movieclip On Target- Duplicate
Hi I am new here, and to actionscript. I am working on a flash movie, and have run into a problem.

In this flash movie, you can drag the circle or square, and lock them on the smaller circle targets. What I would like to do is have a dragable duplicate made at the origin. So, say I could drag three circles, or three squares.

I have relentlessly tried to incorporate duplicateMovieclip(). But have not had any luck.

function dragSetup(clip, targArray) {
clip.onPress = function() {
startDrag(this);
this.beingDragged = true;
};
clip.onRelease = clip.onReleaseOutside=function () {
stopDrag();
this.beingDragged = false;
for (i=0; i<targArray.length; i++) {
targ = targArray[i];
if (eval(this._droptarget) == targ) {
this.myFinalX=targ._x
this.myFinalY=targ._y
this.onTarget = true;
_root.targ.gotoAndStop(2);
break;
} else {
this.onTarget = false;
_root.targ.gotoAndStop(1);
}
}
};
//the variables below will store the clips starting position
clip.myHomeX = clip._x;
clip.myHomeY = clip._y;

clip.myFinalX = 0;
clip.myFinalY = 0;
clip.onEnterFrame = function() {
//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)
// then move the MC back to its original starting point (with a smooth motion)"
if (!this.beingDragged && !this.onTarget) {
this._x -= (this._x-this.myHomeX)/5;
this._y -= (this._y-this.myHomeY)/5;
//if the circle is dropped on any part of the target it slides to the center of the target
} else if (!this.beingDragged && this.onTarget) {
this._x -= (this._x-this.myFinalX)/5;
this._y -= (this._y-this.myFinalY)/5;
}
};
}
allTargets = new Array(targ01, targ02, targ03);
dragSetup(circle,allTargets);
dragSetup(square,allTargets);

Drag And Drop Color Swatches To Target
Hi

I need help please. I am trying to have a row of color swatches that when one of them are dragged onto the target MC that particlar MC assimilates that swatches color. This needs to happen over and over again so that I can keep drtagging new colors over the old colors.
See pic....

Thanks so much.

redstamaster

Drag And Drop Target Stuck To Mouse - Help- See Swf.
Hi, i´ve been going through some tutorials and samples of "drag and drop" flash movies and I always come apon the same bug. The drop target gets "stuck" to the mouse, and when I click the target it just drops down and doesn´t return to its orig. position. This mostly happens when the target in the "lower order" is droped behind a target that is "in front of it" Now I have used the
Code:
this.swapDepths(_root.getNextHighestDepth());
to fix the "order" problem but still the problem some times happens. - You can see the problem in the fla/swf if you drag on of the "lower order targets" under the "front targets".

Does any one know if there is a way to fix this...?

Help This Is Driving Me Nuts Drag And Drop Target Problem...
Hi, hope this all makes sense...

I have a drag and drop thing going in a movie called 2004.swf which when dropped onto the defined area, loads a new swf called cheekymonkey.swf. It works when CTRL Entered. However the main movie is called portfolio.swf. It has a button in it which loads 2004.swf. When I test the portfolio.swf file and click the button to load 2004.swf, it loads fine and the button will drag, but won't load the cheekymonkey.swf when dropped.

The 2004.swf is loaded into level2
The drag button to load cheekymonkey.swf loads it into level5.

Am working in Flash MX

I know it must be a target/levels problem???

PLEASE LET ME KNOW IF ANY ADDITIONAL INFO IS NEEDED!!!

Here's the code on the button which when dropped loads cheekymonkey.swf.

---------------------------------------------------------


on (press) {
startDrag("/01");
}
on (release) {
stopDrag();
if (getProperty("/01", _droptarget) eq "/trigger") {
tellTarget ("/") {
loadMovieNum("cheekymonkey.swf", 5);
}
setProperty("/01", _x, "385");
setProperty("/01", _y, "160");
} else {
setProperty("/01", _x, "385");
setProperty("/01", _y, "160");
}
}

Duplicate Event.Target For Drag N Drop Scenario
Hello,

I'm trying to create a drag and drop scenario in Actionscript 3. When an item on the stage is clicked, that item is duplicated, and that duplicated item is dragged with startDrag().

Essentially I need to duplicate the event.target - is this possible?

Here is my code:


Code:
function duplicateitem(eventObject:MouseEvent) {
activeitem = eventObject.target;
this.addChild(activeitem);
activeitem.x=eventObject.target.x;
activeitem.y=eventObject.target.y;
activeitem.startDrag();
}

item.addEventListener(MouseEvent.MOUSE_DOWN, duplicateitem);
The above code will not work. I need to be able to actually duplicate "item", which is the "eventObject.Target"...

but if I tried something like:


Code:
var activeitem = new item();
I would then need to do this for every unique item on the stage and have a unique function for each of them which I need duplicating...

if anyone knows how to duplicate an object and then have it draggable, that would be an incredible help. thanks

[MX04] Drag And Drop- Locking Object Into Center Of Target...
Hello all,
New member and relatively new Flash user. I created a drag and drop in Flash MX 2004, and I'm trying to find script that will lock the object into the center of the target when it is dragged over, sort of like a magnet effect. Here is the script I currently have on each object:


on(press) {
startDrag(this);
_root.reply.text="";
xstart = this._x;
ystart = this._y;
}

on(release) {
stopDrag();
if (this._droptarget == "/pinottarget") {
_root.reply.text="Correct!";
this.enabled = false;
_root.counter++;
}

else{
_root.reply.text="No, keep trying!";
this._x = xstart;
this._y = ystart;
}
}



If anybody can help me out with the correct script to do what I'm trying to do, I would greatly appreciate it. Attached is the source file. Thanks.

Lee

Drag And Drop Target/show And Hide Move Clip/ AS2
ok i am a bit of an amateur in flash so forgive me if i sound stupid.

i am creating a drag and drop dress-up doll on steroids. its not the normal dress-up doll where all the MCs are on the stage with drag actions on them and you can stack clothes on top of each other. This one is a bit different but i am having trouble getting it to work.

I have some icons (iconMC) of tees in a scrollable movie clip that acts as a product chooser. i also have a file of a model( the doll) wearing the real shirt (shirtMC). i want to create an if/els statement that states something like if the drop target (dragging the icon movie clip to the dolls chest) was a success then show xShirt_mc and hide all the rest of the shirts (aShirt, bShirt, cShirt, dShirt, eShirt) now granted that doesnt sound to difficult but i will have like 125+ shirts in the product chooser and the doll. am i going to have to write the visibility off action for all the remaining clips for all of the shirts in the product chooser. there must be an easier way to do this

I also need to make a button that checks to see which shirt is visible and sends you to a html page on a related e-commerce site. so that button would have 125+ different pages to go to depending on which clip was visible

Thank you
this is done in actionscript 2

Creating Drag And Drop - Multiple Objects To Single Target + Specific Feedback
Hi,

I've created a simple drag and drop flash file. What I need to know though is if I can have multiple objects being dragged to a single target? For example, I want an additional object paper_dr to also be dragged to the target Paper_Text.

And if so, can I provide a response to the user based on which object they dragged (using the single dynamic text field?).

The code is below...

Thanks in advance!


Code:
var dict = new Dictionary ();

// =================== START USER Config =====================
// Insert as many "dict[text_box] = movie;" statements you like
// Replace: text_box by the name of a matching dynamic text_box
// movie by the name of movie instances users can move around.

dict[Paper_Text] = Box_dr;
dict[Plastics_Text] = Plastic_dr;
dict[Glass_Text] = Bottle_dr;

// Do NOT change/delete any other line. Also make sure to respect
// the syntax, e.g. dont forget the ";" at the end of each line.
// ===================== END USER Config ====================

var hits = 0; // counts succesful hits
var max = 0; // used to compute dictionary length

// For each item in the dictionary we add event listeners
// "for each" will loop through the values ... not the keys

for each (var item in dict)
{
item.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
item.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
item.buttonMode = true; //needed for the hand cursor to work
max = max + 1;
}


// Define a mouse down handler (user is dragging)
function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
// we should limit dragging to the area inside the canvas
object.useHandCursor = true;
object.startDrag();
}

function mouseUpHandler(evt:MouseEvent):void {
var obj = evt.target;
// obj.dropTarget will give us the reference to the shape of
// the object over which we dropped the circle.
var target = obj.dropTarget;
// If the target object exists the we ask the test_match function
// to compare moved obj and target where it was dropped.
if (target != null)
{
test_match(target, obj);
}
obj.stopDrag();
}

function test_match(target,obj) {
// test if the pairs match
if (dict[target] == obj)
{
// we got a hit
hits = hits+1;
Outcome_text.text = "That item has just been successfully sorted for recycling!";
// make the object transparent
obj.alpha = 0.5;
// kill its event listeners - object can't be moved anymore
obj.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
obj.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
// Test if we are done
if (hits == max)
{
// here we should play an animation
Outcome_text.text = "Congratulations& youve just recycled all the packaging in the workplace!";
}
}
else
{
Outcome_text.text = "Unfortunately, that wasnt correct. Review the content in this module, and try again.";
}
}

Drag And Drop MC, Involves Polygonal Boundary, Drop Into Trash.
Hello. This is my desperate problem:

I am creating a circuit diagram designer.
There is basically instructions on the left, in a scrolling textbox (taken care of) and above that a rectangle with a bunch of components in it.

You need to be able to drag the circuit part from the side bar (a duplicate, so that the original remains in the same spot), and to a square on the grid on the stage of this program(Should snap to place...). Each clone should be able to be moved. Like so: You Press on a MC to drag it, the thing you are dragging to the stage is of course a clone. You release the mouse button, so it drops on the grid. It snaps into place. *Oops, you made a mistake. You press on it again, it is draged by your mouse to another square, and does not make a clone. *mind Changes... I dont want to use this one any more. You press on the MC, drag it to a bin which animates to show you the MC is being dragged over it. You release, the MC in question is deleted/removed...

You need to be able to rotate circuit parts by clicking on it so that it highlights, then pressing space bar.

It must also be possible to delete a duplicate by dragging it to the trash (an image/ MC), and last but not least, it is required to save the contents of the stage, or print them off.

Please note that to print it off, there are 2 input boxes outside the stage. One for the title, and one for the Users' Name. When they click on the print button, the two dynamic text fields must retrieve the values from the box outside of the programs' stage.

One Last detail: The cloned objects to be dragged around net to be in a six co-ordinate polygonal boundary, so that no-one can place any objects outside of the stage.

If anyone can help me, i would greatly appriciate it. I need to get this done asap. The graphics have been taken care of, it is just the coding to be done now. HELP, HELP PLEASE!




Thanks - Matt K

[fmx] Drag And Drop With Multiple Drop Locations
Hi

I am trying to make a draggable object have two drop locations, but it will still only drop to one. Please if anyone can help me or notice my mistake it would be really appreciated.


on (release) {
if (_root.DragMotor._droptarget == "/Socket2") {
_root.DragMotor._x = _root.Socket1._x;
_root.DragMotor._y = _root.Socket1._y;
_root.CheckMotorDrop();
} else {
_root.MotorDropped = 0;
}
if (_root.DragMotor._droptarget == "/Socket1") {
_root.DragMotor._x = _root.Socket2._x;
_root.DragMotor._y = _root.Socket2._y;
_root.CheckMotorDrop();
} else {
_root.MotorDropped = 0;
}

function CheckMotorDrop () {
//set the speech bubble to give information
_root.txtSpeech = "You have added a motor to the circuit.";
setProperty(_root.DragMotor, _width, 55);
setProperty(_root.DragMotor, _height, 55);
_root.MotorPowered = 1;
_root.DragMotor.play();
_root.MotorDropped = 1;
}


Thanks for your time, Matt.

Copyright © 2005-08 www.BigResource.com, All rights reserved