Here is the source code:
- Code: Select All Code
item1.visible = false;
item2.visible = false;
item3.visible = false;
item4.visible = false;
var currentslotnum:int = 1;
var numberStored:int = 1;
var item1x:int = 0;
var item1y:int = 0;
var item2x:int = 0;
var item2y:int = 0;
var item3x:int = 0;
var item3y:int = 0;
var item4x:int = 0;
var item4y:int = 0;
var slotBool:Boolean = false;
var newlyOpenSpot:int = 1;
item1Button.addEventListener(MouseEvent.CLICK, item1Buttonclick);
function item1Buttonclick(event:MouseEvent):void
{
addToSlot(item1);
}
item2Button.addEventListener(MouseEvent.CLICK, item2Buttonclick);
function item2Buttonclick(event:MouseEvent):void
{
addToSlot(item2);
}
item3Button.addEventListener(MouseEvent.CLICK, item3Buttonclick);
function item3Buttonclick(event:MouseEvent):void
{
addToSlot(item3);
}
item4Button.addEventListener(MouseEvent.CLICK, item4Buttonclick);
function item4Buttonclick(event:MouseEvent):void
{
addToSlot(item4);
}
function addToSlot(item)
{
if(slotBool)
{
if(!item.found)
{
item.x = getChildByName("itemslot" + newlyOpenSpot).x;
item.y = getChildByName("itemslot" + newlyOpenSpot).y;
item.numberStored = newlyOpenSpot;
if(item == item1)
{
item1x = item.x;
item1y = item.y;
}
if(item == item2)
{
item2x = item.x;
item2y = item.y;
}
if(item == item3)
{
item3x = item.x;
item3y = item.y;
}
if(item == item4)
{
item4x = item.x;
item4y = item.y;
}
item.found = true;
slotBool = false;
}
}
if(!slotBool)
{
if(!item.found)
{
item.x = getChildByName("itemslot" + currentslotnum).x;
item.y = getChildByName("itemslot" + currentslotnum).y;
item.numberStored = currentslotnum;
if(item == item1)
{
item1x = item.x;
item1y = item.y;
}
if(item == item2)
{
item2x = item.x;
item2y = item.y;
}
if(item == item3)
{
item3x = item.x;
item3y = item.y;
}
if(item == item4)
{
item4x = item.x;
item4y = item.y;
}
item.found = true;
currentslotnum++;
}
}
item.visible = true;
}
var searcher:int = 0;
function removeSlot(item)
{
if(item.found)
{
slotBool = true;
item.found = false;
if(item.numberStored == 1)
{
newlyOpenSpot = item.numberStored;
}
if(item.numberStored == 2)
{
newlyOpenSpot = item.numberStored;
}
if(item.numberStored == 3)
{
newlyOpenSpot = item.numberStored;
}
if(item.numberStored == 4)
{
newlyOpenSpot = item.numberStored;
}
if(item.numberStored == 5)
{
newlyOpenSpot = item.numberStored;
}
if(item.numberStored == 6)
{
newlyOpenSpot = item.numberStored;
}
}
}
item1.addEventListener(MouseEvent.MOUSE_DOWN, item1ToDrag);
function item1ToDrag(event:MouseEvent):void
{
item1.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, item1ToDrop);
function item1ToDrop(event:MouseEvent):void
{
item1.stopDrag();
if(item1.hitTestObject(test1))
{
item1.x = test1.x;
item1.y = test1.y;
removeSlot(item1);
}
else
{
item1.x = item1x;
item1.y = item1y;
}
}
item2.addEventListener(MouseEvent.MOUSE_DOWN, item2ToDrag);
function item2ToDrag(event:MouseEvent):void
{
item2.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, item2ToDrop);
function item2ToDrop(event:MouseEvent):void
{
item2.stopDrag();
if(item2.hitTestObject(test2))
{
item2.x = test2.x;
item2.y = test2.y
removeSlot(item2);
}
else
{
item2.x = item2x;
item2.y = item2y;
}
}
item3.addEventListener(MouseEvent.MOUSE_DOWN, item3ToDrag);
function item3ToDrag(event:MouseEvent):void
{
item3.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, item3ToDrop);
function item3ToDrop(event:MouseEvent):void
{
item3.stopDrag();
if(item3.hitTestObject(test3))
{
item3.x = test3.x;
item3.y = test3.y
removeSlot(item3);
}
else
{
item3.x = item3x;
item3.y = item3y;
}
}
item4.addEventListener(MouseEvent.MOUSE_DOWN, item4ToDrag);
function item4ToDrag(event:MouseEvent):void
{
item4.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, item4ToDrop);
function item4ToDrop(event:MouseEvent):void
{
item4.stopDrag();
if(item4.hitTestObject(test4))
{
item4.x = test4.x;
item4.y = test4.y
removeSlot(item4);
}
else
{
item4.x = item4x;
item4.y = item4y;
}
}
And attached is the swf for you to see my problem first hand.
Thanks in advance to anyone who can help.