PDA

View Full Version : Possible to reset drag and drop items without restarting movie clip?



g4zilla
May 11th, 2009, 04:50 PM
Sounds strange, but let me explain. What the user sees: Loading the page, color swatches fade in and slide over into place, row by row. Once in place, user can drag and drop swatches around, place side-by-side, etc.

That much, I've got. (thanks to hacking up a template) What I lack: The script necessary to attach to a button so that all swatches can be reset back into place where they were, and not generate a replay of the initial movie clip from the beginning. (a goto and play is not what I'm looking for)

Here's my code so far:


//
stop();
import mx.transitions.Tween;
import mx.transitions.easing.*;

tn_mc._visible = false;
var intervalId:Number;
var initial_alpha:Number = 20;
var i:Number = 1;
var j:Number = 0;
var k:Number = 0;
var duration:Number = 250;

// maxCount is length of label_list OR link_list
// OR total frames inside "thumbnails"
var maxCount:Number = 48;

// length of label_list array and length of link_list array must be equal
// to length of frames inside "swatches" movieclip

var label_list:Array = new Array("All White", "Wimborne White", "Pointing", "White Tie", "James White", "Clunch", "Strong White", "Great White", "House White", "New White", "Tallow", "Ringwold Ground", "Slipper Satin", "Lime White", "Off-White", "Dimity", "Joa's White®", "Archive®", "Matchstick", "String®", "Savage Ground", "Cord", "Cream", "Cat's Paw", "Blackened", "Skimming Stone", "Cornforth White®", "Pavilion Gray", "LampRoom Gray®", "Charleston Gray", "Shaded White", "Stony Ground", "Hardwick White®", "French Gray", "Blue Gray", "Pigeon", "Old White", "Bone®", "Fawn", "Light Gray", "Mouse's Back®", "Dauphin", "Elephant's Breath®", "Smoked Trout®", "Dead Salmon®", "London Stone", "Buff", "London Clay");

var link_list:Array = new Array("www.still-need-to-add.com");

function createThumbnails()
{
duplicateMovieClip( tn_mc, "tn" + i, i );
this["tn" + i].gotoAndStop(i);

position_x = j*75+100;
position_y = 30;
j++;
if( i % 13 == 0 ) { j = 0; k++; }

this["tn" + i]._x = position_x;
this["tn" + i]._alpha = initial_alpha;
this["tn" + i].swatch_label.text = label_list[i-1];
this["tn" + i].swatch_url = link_list[i-1];
this["tn" + i].swatch_button._visible = false;
random_y = random(450);

new Tween(this["tn" + i], "_alpha", Strong.easeInOut, initial_alpha, 100, 3, true);
new Tween(this["tn" + i], "_x", Strong.easeOut, position_x + 300 - i, position_x - i, 3, true);
new Tween(this["tn" + i], "_y", Elastic.easeInOut, position_y + 200 + i*5, position_y + i*5, 3, true);

this["tn" + i].swatch_button.onPress = function()
{
this._parent.swapDepths(_root.getNextHighestDepth( ));
this._parent.startDrag();
}
this["tn" + i].swatch_button.onRelease = function()
{
this._parent.stopDrag();
}
this["tn" + i].swatch_link.onRelease = function()
{
getURL( this._parent.swatch_url );
}
if(i >= maxCount)
{
clearInterval(intervalId);
for( i = 1; i <= maxCount; i++ )
this["tn" + i].swatch_button._visible = true;
}
i++;
}
intervalId = setInterval(this, "createThumbnails", duration);

As i have no code attached to my reset button, I've got nothing to show there.

I've done a ton of searching on various forums, but haven't seen anything that would work for me. Thanks for any help with this!

SandeR2
May 12th, 2009, 04:35 AM
after the Tween you should somehow put all the x,y locations of the objects into an array. then after pressing the Reset button give then the x,y from the array corresponding to the object.

Sorry I can't give you any code, but I hope you get the idea what to do or maybe someone else can help you with the tip i gave you.

_succes

g4zilla
May 12th, 2009, 09:44 AM
SandeR2: That sounds like that could work! I'll have to dig in and see if I can figure it out (I'm a Flash noob). Thanks for your help!