-
help with depth
hi guys , i made an inventory for my game but the problem is that when i click and drag an object over the other one it overlaps it
so i want to know what to do to make it , when i click on an object, it makes it at the top of all the other objects in the inventory (makes it's depth the lowest it think)
i wish you guys can help me :D
-
Hi,
This might point you in the right direction
PHP Code:
myButton.onPress = function()
{
this.swapDepths(_root.getNextHighestDepth());
};
-
yeah thanks that fixed the depth issue
but it still overlaps the existing item
here's the swf:http://filz.us/25xM
it doesn't overlap it from the first time you put it in the slot , it happens like 2\10 times
-
I don't see any issues o.O can you explain better?
I drag and drop the items, and the dragged item always overlap (is always on top) the already placed items on the slots...
-
yeah i don't want the object to overlap the other one when it is put above it
i want it to go back to it's original place or slot when it founds another object in the place it was put into , see, i programmed it to go to the blue box i have drawn under the slots but sometimes it doesn't go to the box and it overlaps an object
-
Hi,
That's a problem with some other code, not the depths, I guess it's not saying when a slot is full (setting a var perhaps), and without seeing the fla or any other code, then it's pretty impossible to predict.
-
ok here is the code on the first frame
PHP Code:
items_moving()
function items_moving(){
for(i=0 ; i<4;i++){
var Items:MovieClip = this["item"+i]
Items.onPress = function(){
this.startDrag();
}//Items.onPress END
Items.onRelease = function(){
this.stopDrag();
draged_item = this
collision_detect()
}//Items.onRelease END
}//for END
}//items_moving function END
function collision_detect(){
for(s=0 ; s<8;s++){
var slots:MovieClip = this["slot"+s]
if(draged_item.hitTest(slots)){
if(slots.id == "full"){
draged_item._x = 258.4
draged_item._y =251.3
}else if(slots.id == "empty"){
slots.id = "full"
draged_item._x = slots._x
draged_item._y = slots._y
}
}else{
slots.id = "empty"
}
}//for END
}//collision_detect function END
code in the every slot
PHP Code:
onClipEvent(load){
this.slot = 2
this.id = "empty"
}
the blue box is just temporary just to test the collision and overlaping
-
What I do in that cases, is to use variables when the dropTarget or hitTest event happens that set a Slot to "occupied". I create the slots programmatically with a for loop and then I check for the occupied slot this way:
var Occupied:Boolean;
var defaultPosition:Number = draggedItem._x;
draggedItem.onRelease = function()
{
for ( i = 0; i <= 8; i++)
{
if(this.dropTarget == _root["/"+Slot+i])
{
if(_root["Slot"+i].Occupied != true)
{
this._x = _root["Slot"+i]._x
_root["Slot"+i].Occupied = true;
}
}
else
{
this._x = defaultPosition;
}
}
}
Something like that...I can make you an .fla later, what version of flash are you using?
-
Hi,
That's decompiled code and it's not the same as the decompiled code I have here from your swf, why not attach or link to the *.fla file.
-
1 Attachment(s)
no this is the same script , i just removed some useless scripts but it didn't made so much difference
-
Hi,
This tutorial will help you learn how to achieve what you wish to do http://www.flashkit.com/tutorials/Dy...-212/index.php
-
Hi,
If you are unable to change the tutorial to your needs then here it is converted, CS5
-
umm can you convert it to cs3 ? thanks
-
Hi,
Sorry, I am unable to lower the CS version, perhaps somebody else can do it for you, or you could go to the tutorial and do it yourself.
-
uuum , i was lost at the middle when he starts to do on(press) function , i don't know does he replace this function
in my code , is there some thing wrong with it ? like the hittest part ?
-
Hi,
Basically the tutorial way is to create arrays from the start.
The onPress function checks/remakes the array status using the hitTest.
The onRelease function does the same again once released.
I did the change the tutorial a lot, especially to make it work like your original one, you could however decompile mine, if it is the last straw.
-
i asked a friend to convert for me
thanks mate it works perfectly , but there are some parts i don't understand, like what does break and continue mean ?
also what is _loc3 variable made for ?
-
Hi,
Glad you got it working.
break; = stop/discontinue the current loop
continue; = skip this part of the loop and do next or something similar
As for _loc, there should not be any there, that usually appears within decompiled code in place of a var name, so you can swap all _loc* of the same value for anything you like, eg, name all occurences of _loc3 with myVar3 perhaps, and all _loc2 for myVar2.
-
ok thanks man for your help , i really appreciate it ^^