Carousel: Bring clicked item to front

Before I start, I would like to say I have searched the forums for help. I have searched google. I hope this is a very popular topic. But I haven’t found help for my little problem…

So, like everyone else I watched the gotoandlearn video on carousels, but I hate using the library so anything, so I am in the process of rewriting it. Here’s my situation. I want to be able to click on a item and have it swing around and stop in the in the middle. Well, I can get it to find the middle of it’s rotation, but I can’t find out how to get it to make sure its in the front.

Below is my entire code. I will bold the section that is the problem. Below the code will be the xml if you wanna give it a test.

Will will see the main problem lies in an if statement in the mover function. I haven’t tried every way I can think of to get it to detect being in front, but nothing is working…

Thanks in advance for the help/looking at this.

code:


import flash.filters.BlurFilter

var radiusX:Number = 75;
var radiusY:Number = 15;
var centerX:Number = Stage.width/2;
var centerY:Number = Stage.height/2;
var speed:Number = 0.05;
var home:MovieClip = this;
var checked:Boolean = false;
var clp:MovieClip = null;
var clpArr:Array = new Array();

var xml:XML = new XML();
xml.ignoreWhite = true

xml.onLoad = function(){
    var nodes = this.firstChild.childNodes;    
    for(var i=0;i<nodes.length;i++){
        var container:MovieClip = home.createEmptyMovieClip("item"+i,i+1);
        var up:MovieClip = container.createEmptyMovieClip("icon",container.getNextHighestDepth());
        var down:MovieClip = container.createEmptyMovieClip("reflect", container.getNextHighestDepth());
        
        container.angle = i * ((Math.PI*2)/nodes.length);
        container.onEnterFrame = mover;
        container.count = i+1;
        
        clpArr.push(container);
        
        var mcLoader:MovieClipLoader = new MovieClipLoader();
        var listen = new  Object(); 
        mcLoader.addListener(listen);
        mcLoader.loadClip(nodes*.attributes.image, up);
        
        var mcLoader2:MovieClipLoader = new MovieClipLoader();
        var listen2 = new  Object(); 
        mcLoader2.addListener(listen2);
        mcLoader2.loadClip(nodes*.attributes.image, down);        
        
        listen.onLoadInit = function(clip:MovieClip){
            clip._x = 0;
            clip._y = 0;            
                
            clip.onRollOver = function(){
                this.createTextField("txt",10000,0,0,0,0);
                this.txt.autoSize = "left";
                this.txt.text = "Bottle" + this._parent.count;
                this.txt._x = r._x;
                this.txt._y = r._x - 15;
            }
                
            clip.onRollOut = function(){
                this.txt.removeTextField();
            }
            
            clip.onPress = function(){
                checked = true
                clp = this._parent;
            }
        }
                
        listen2.onLoadInit = function(clip:MovieClip){                
            clip._x = up._x;
            clip._y = 300;
            clip._yscale *= -1;
            
            gradient(clip);    
        }        
    }
}

xml.load("icons.xml");

**function mover(){
    this._x = Math.cos(this.angle) * radiusX + centerX;
    this._y = Math.sin(this.angle) * radiusY + centerY;
    var s:Number = this._y / (centerY + radiusY);
    this._xscale = this._yscale = s*100;
    this.swapDepths(Math.round(this._xscale  + 100));
        
    if(checked == false){
        this.angle += speed;
    }else{
        if(clp.getDepth() < 199 && (clp._x <= centerX - clp._width/2 || clp._x >= centerX + clp._width/2)){
            if(clp._y - clp._width/2 > centerY ){                
                this.angle -= 50;
            }else{                
                this.angle += 50;
            }
        }else{
            trace("meow");
        }
    }**    
    
    if(this._y < centerY + radiusY/2 + 5){        
        var blurFilter:BlurFilter = new BlurFilter(centerY - this._y+2,centerY - this._y+2,2);
        var myArr:Array = new Array();
        myArr.push(blurFilter);
        this.filters = myArr;
    }else{
        this.filters = null;
    }
}

this.onMouseMove = function(){
    speed = (this._xmouse-centerX)/2000
}

function gradient(down:MovieClip){
    con = down._parent;
    var clipName:MovieClip = con.createEmptyMovieClip("clp",con.getNextHighestDepth());

    var boxProperties:Object = {x:0, y:0, w:down._width, h:down._height/2};
    var colArray:Array = [0xFF00FF, 0x0000FF]; 
    var alpArray:Array = [40, 0]; 
    var sprArray:Array = [0, 0xFF];
    var matrixData:Object = {matrixType:"box", x:boxProperties.x, y:boxProperties.y, w:boxProperties.w, h:boxProperties.h, r:1.5708};
    
    with (clipName) { 
        moveTo(boxProperties.x, boxProperties.y);
        beginGradientFill("linear", colArray, alpArray, sprArray, matrixData);
        lineTo(boxProperties.x + boxProperties.w, boxProperties.y);
        lineTo(boxProperties.x + boxProperties.w, boxProperties.y + boxProperties.h);
        lineTo(boxProperties.x, boxProperties.y + boxProperties.h);
        lineTo(boxProperties.x, boxProperties.y);
        endFill()
    }
    clipName._x = down._x;
    clipName._y = down._y - 150;
    
    clipName.cacheAsBitmap= true;
    down.cacheAsBitmap = true
    
    down.setMask(clipName);
}

xml:


<?xml version="1.0" encoding="UTF-8"?>

<icons>
    <icon image="images/icon7.png"></icon>
    <icon image="images/icon8.png"></icon>
    <icon image="images/icon9.png"></icon>
</icons>