PDA

Volledige versie bekijken : drag en drop positie wisselen


publikum
%Europe/Berlin %681 %2008, 16:20
ik heb een simpel scriptje gemaakt om twee items te kunnen verplaatsen over het beeld. nu wil ik dat wanneer ik het ene item versleep naar het andere item hij het onderliggende item verplaatst naar de oude locatie van het item wat ik probeer neer te zetten op de locatie van item 2. Ik hoop dat ik het zo duidelijk uitleg.

script:

item1._x = 40;
item1._y = 40;

item2._x = 150;
item2._y = 40;

item1.onRelease = function(){
this.stopDrag();
}
item1.onPress = function(){
this.startDrag();
this.swapDepths(this.getNextHighestDepth());
}
item1.onReleaseOutside = function(){
item1.stopDrag();
}




item2.onRelease = function(){
this.stopDrag();
}
item2.onPress = function(){
this.startDrag();
this.swapDepths(this.getNextHighestDepth());
}
item2.onReleaseOutside = function(){
item1.stopDrag();
}

Jan
%Europe/Berlin %699 %2008, 16:47
Zo:
item1._x = 40;
item1._y = 40;
item2._x = 150;
item2._y = 40;
var aantal:Number=2

for (var i:Number = 1; i <= aantal; i++)
{
this["item" + i].onPress = function()
{
this.x = this._x;
this.y = this._y;
this.startDrag();
this.swapDepths(this._parent.getNextHighestDepth() );
};
this["item" + i].onRelease = this["item" + i].onReleaseOutside = function ()
{
stopDrag();
for(var i:Number=1; i<=aantal; i++)
{
if(this.hitTest(this._parent["item"+i])&& this!=this._parent["item"+i])
{
this._parent["item"+i]._x=this.x;
this._parent["item"+i]._y=this.y;
break;
}
}
};
}

Of zo: (de muis moet hier het item waar je het op laat vallen wel raken);

item1._x = 40;
item1._y = 40;
item2._x = 150;
item2._y = 40;
var aantal:Number=2

for (var i:Number = 1; i <= aantal; i++)
{
this["item" + i].onPress = function()
{
this.x = this._x;
this.y = this._y;
this.startDrag();
this.swapDepths(this._parent.getNextHighestDepth() );
};
this["item" + i].onRelease = this["item" + i].onReleaseOutside = function ()
{
stopDrag();
eval(this._droptarget)._x = this.x;
eval(this._droptarget)._y = this.y;
};
}

Groeten,
Jan

publikum
%Europe/Berlin %770 %2008, 18:29
precies wat ik bedoel. thnx