[F8 AS2] Fly up and hover

Hi all, I’m working on a little navigation here where several icons will fly up to a certain height and then hover around, kinda like a flying insect might. Most of my actionscripting experience has been pretty basic so far, and i’m having a little trouble getting this thing to do exactly what i want.

these are things that i would like to happen:
– the icons fly up sequentially, instead of all at once
– the icons fly up to a less uniform height (more variance on the Y axis)

these are things that really need to be fixed, but i can’t figure out how:
– if you rollover the icons too fast, they go to a negative scale(which flips them over)

also, i’m sure this code isn’t the most efficient, and there are a few onEnterFrames that i could probably get rid of, but when i tried deleting any, it would break the code. So ANY suggestions on how to clean up or optimize this code would be much appreciated, even if you have to rip on my abilities, i don’t care, i just need help. Thanks…


var root:MovieClip = this;
var numIcons:Number = 10;
var maxHeight:Number = 100; //max height for icons to fly
var speed = 8;
var stageW:Number = Stage.width;
var stageH:Number = Stage.height;


//------------initialize icons----------------\\
function initIcons() {
    for (i=1; i<numIcons+1; i++) {
        t = this.attachMovie("pIcon", "pIcon"+i, this.getNextHighestDepth());
        t._x = ((stageW-50)/numIcons)*i; //space icons along X on stage
        t._y = 500;
        t._xscale = t._yscale=getRN(35, 50); //random scale
        t.onEnterFrame = function() {
            //if below maxHeight
            if (this._y<=maxHeight+30) {
                hover(this);
            } else {
                //fly towards maxHeight
                this._y += (maxHeight-this._y)/speed;
            }
        };
        
        
        t.iconHit.onRollOver = rolledOver;
        t.iconHit.onRollOut = rolledOut;
    }
}


function rolledOver() {
    trace(this._parent+" was rolled over");
    var p:MovieClip = this._parent;
    p.swapDepths(root.getNextHighestDepth());
    p._x = root._xmouse;
    p._y = root._ymouse;
    var pXscale:Number = this._parent._xscale;
    this.onEnterFrame = function() {
        //increase scale: current scale + 200
        p._xscale = p._yscale += ((pXscale+100)-p._xscale)/4;
    };
}


function rolledOut() {
    //record current scale
    var pXscale:Number = this._parent._xscale;
    var flyAway:Number = getRN(-100,100);
    this.onEnterFrame = function() {
        //when roll off, fly away to the left or right
        this._x += (flyAway - this._x)/2;
        //scale back to original scale
        this._parent._xscale = this._parent._yscale += ((pXscale-100)-this._parent._xscale)/4;
        //if back to original scale delete the scale down
        if (Math.round(this._parent._xscale) == Math.round(pXscale - 100)) {
            delete this.onEnterFrame;
        }
    };
}

//random number between min and max
function getRN(minNum:Number, maxNum:Number):Number {
    return (minNum+Math.floor(Math.random()*(maxNum+1-minNum)));
}


function hover(target) {
    //if icon gets too close to the right edge, bring it back
    if (target._x>=stageW-20) {
        target._x -= 30;
    } else if (target._x<=20) {
        //if icon gets too close to the left edge, bring it back
        target._x += 30;
    } else {
        //random x and y position, creates jitter
        target._x += (getRN(this._x-20, this._x+20)-this._x)/6;
        target._y += (getRN(this._y-10, this._y+20)-this._y)/6;
    }
    //trace("hovering");
}
initIcons();

[FONT=Courier New][/FONT]