A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Need help with swaping depths.

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2

    resolved [RESOLVED] Need help with swaping depths.

    I have button that when clicked on creates a movie clip with the following script.

    Code:
    spots[spots.length] = this.attachMovie("spot","spot",this.getNextHighestDepth());
    where spots is a previously declared array.

    I have the following code in a found in a function elsewhere.

    Code:
    for(i=0;i<spots.length;i++)
    {
    	if(xmouseGrid == spots[i]._x && ymouseGrid == spots[i]._y)
    	{
    		spots[i].swapDepths(spots[i-1]);
    		break;
    	}
    }
    The if statement and the condition under which it executes are not relevant.
    What matters is that the swapDepths function simply does nothing here.

    I did the following test to try and find out what was wrong.

    Code:
    for(i=0;i<spots.length;i++)
    {
    	if(xmouseGrid == spots[i]._x && ymouseGrid == spots[i]._y)
    	{
    		trace(spots[i].getDepth() + " : " + spots[i-1].getDepth());
    		spots[i].swapDepths(spots[i-1]);
    		trace(spots[i].getDepth() + " : " + spots[i-1].getDepth());
    		break;
    	}
    }
    And the trace displayed the same exact message both times, nothing had happened between the two traces.

    I did a lot of testing and it seems that swapDepths does not work properly when the mc's involved are a part of an array.
    There is another place where I swap a different mc's depth with that of spots[i] but it swaps depth with the wrong instance of the spots array.

    Can anyone tell my why this is or if there is anyway of fixing it?
    Any help is greatly appreciated.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Each movie clip need unique identifier. Try this something like this...
    Code:
    spots[spots.length] = this.attachMovie("spot", "spot"+this.getNextHighestDepth(), this.getNextHighestDepth());

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thank you very much, it all works correctly now.

Tags for this Thread

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