help with depth
A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: help with depth

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    13

    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

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,053
    Hi,

    This might point you in the right direction
    PHP Code:
    myButton.onPress = function()
    {
        
    this.swapDepths(_root.getNextHighestDepth());
    }; 

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    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

  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    951
    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...
    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  5. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    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

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,053
    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.

  7. #7
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    ok here is the code on the first frame

    PHP Code:

    items_moving
    ()

    function 
    items_moving(){

        
        for(
    i=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=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

  8. #8
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    951
    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 Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,053
    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.

  10. #10
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    no this is the same script , i just removed some useless scripts but it didn't made so much difference
    Attached Files Attached Files

  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,053
    Hi,

    This tutorial will help you learn how to achieve what you wish to do http://www.flashkit.com/tutorials/Dy...-212/index.php

  12. #12
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,053
    Hi,

    If you are unable to change the tutorial to your needs then here it is converted, CS5
    Attached Files Attached Files

  13. #13
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    umm can you convert it to cs3 ? thanks

  14. #14
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,053
    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.

  15. #15
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    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 ?

  16. #16
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,053
    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.

  17. #17
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    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 ?

  18. #18
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,053
    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.

  19. #19
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    ok thanks man for your help , i really appreciate it ^^

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com