A Flash Developer Resource Site

# Thread: change depths in as3

1. ## change depths in as3

hi,
i´m trying to change depths of sprites that makes an elliptical movement.

to make some perspective i scaled the sprites according to their y position and i´m trying to change their depths dynamically.

As i expected swapDepths is no longer on AS3 so i tried to use setChildrenIndex() method, as adobe recommends. So the problem is that the index that i need to pass must be in range of the stage number of children. so i can´t pass just a Math.floor() of the y position of the sprites, ´cause it throws an error.

my pain is finding a way to calculate the correct depth of each sprite according to it´s y position

now i´ve got something like this on my onEnterFrame handler

Code:
```for (i=0;i<sprites.length;i++)
{
// first define the angle of each element
sprites[i]._angle += speed;

// use sine and cosine to set the x and y position of each element, multiply by the radius factor and add the centerX value
sprites[i].x = Math.cos(sprites[i]._angle) * radiusX + centerX;
sprites[i].y = Math.sin(sprites[i]._angle) * radiusY + centerY;

// scale the sprites acoording to it's y position to create an illusion of some perstpective
s = sprites[i].y / (radiusY + centerY);
sprites[i].scaleY = sprites[i].scaleX = s;
sprites[i].alpha = s + 0.3;
depth = ???;

stage.setChildIndex(sprites[i], depth);
}```
i´m trying to find a way to calculate the correct index (or depth)...

i imagine something like this (but not exactly this)

but i´s not good

is there an easy way to do it?

thanks
Chan

2. You should be able to use swapChildren, if you have a reference to two sprites that you want in reverse order.

3. hi guys,
problem solved.
thanks a lot to you both :-)

#### Posting Permissions

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

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap