|
-
help returning a Drag and Drop
Hi everybody on the forum.
I have come across a problem with returning a dragged object back to its original X,Y and am wondering if anyone could help. I am looking for a way for the user to control the return of a dragged object via some kind of function or event handler such as a Key Down ( a mouse up/down would probably cause some conflicts).
The end goal is for the interface screen to be resetable on the users request after moving objects round.
any help would be greatly apprecaited
Thank you
Mark Hollas
-
Just make a button or keypress that changes the _x and _y properties of the object that you want to replace, to the original coordinates eg:
btn_mc.onPress=function(){
_root.obj._x=100;
_root.obj._y=100;
}
You could add a easing script or attach the script to any event that the user can control, its up to you.
-
Thanks that does work.
I do however have another question if you would be so kind. I have over 50 objects that are movable, the way you suggested script looks, I would have to enter each X,Y indiviually for each object. Is there a way to return all the object to their X.Ys with less code, maybe something that will recognize the objects X,Y so I dont have to enter it by hand? I would really appreciate a little help on how to do this. I am fairly new to scripting, I can write event handlers but not so good with variables and arrays( all the beef in scripting)
thank you very much
-
There are a few ways. I dont have the time today to give you a script, but it will be more fun for you to do it yourself.
You could use an array with coordinate values for your clips.
An array is created like so
var myArray:Array = new Array(value1,value2......valuex);
I suggest that you get a copy of the actionscript reference ebook to have as a source of methods and properties of the actionscript language.
An array could store all of your x and y values for your objects. Then you will need some script to access the arrays and return the objects to there original positions.
btn_mc.onPress=function(){
for(i=0;i<myArray.length;i++){
_root.obj[i]._x=myArray[i];
}
}
Ok, arrays start at 0, and the square brackets are a reference to the position within the array that each object is accessing. So if you correspond the id of the obj with the correct array value eg obj1_mc might be the first so it would reference myArray[0] and so on. The for loop goes through all values of the array and changes the object _x for you. This can get complicated and messy if you have too many objects and then you would be better off using a class or component, but i dont have time to tell you about those now, spend some time looking them up. Object Oriented Programming will allow you to do the sort of multiply object manipulation that you want it will take some study though.
Good Luck.
-
sorry to take so long to get back to you.
Thanks for all your help. I ended up getting the results I wanted, now im studying up to make it more efficient.
Thanks again!
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
|