Introducing random _alpha fade in/out speeds

I have some code I have affixed to an mc on the stage, and everything works but I am attempting to modify the _alpha state of the mc according to the following:

• Dynamic fade in/fade out of the mc with random fade in/fade out speeds.

  • When mc fades out, it is removed from the stage and a new mc is duplicated and reintroduced with its own unique parameters, two of which (speed & width) I have accomplished with the code below.

This is the code I have affixed to the mc on the stage:

onClipEvent (load) {

//
width = 1024;
height = 768;
speed = Math.round(Math.random()*10)+1;

//initial positions
x = this._x=Math.random()*width;
x_new = Math.random()*width;

// ascribes each bar a unique width
this._xscale =75+Math.random()*300;
}

onClipEvent (enterFrame) {

//x-axis movement
if (x_new>this._x) {
sign_x = 1;

} else {
sign_x = -1;
}

dx = Math.abs(x_new-this._x);
if ((dx>speed) || (dx<-speed)) {

this._x += sign_x*speed;
} else {
x_new = Math.random()*width;
}

}

Any suggestions? Thanks.

what do you exactly need ?

[quote=warw1ck;2330770]I have some code I have affixed to an mc on the stage, and everything works but I am attempting to modify the _alpha state of the mc according to the following:

• Dynamic fade in/fade out of the mc with random fade in/fade out speeds.

  • When mc fades out, it is removed from the stage and a new mc is duplicated and reintroduced with its own unique parameters, two of which (speed & width) I have accomplished with the code below.

This is the code I have affixed to the mc on the stage:

onClipEvent (load) {

//
width = 1024;
height = 768;
speed = Math.round(Math.random()*10)+1;

//initial positions
x = this._x=Math.random()*width;
x_new = Math.random()*width;

// ascribes each bar a unique width
this._xscale =75+Math.random()*300;
}

onClipEvent (enterFrame) {

//x-axis movement
if (x_new>this._x) {
sign_x = 1;

} else {
sign_x = -1;
}

dx = Math.abs(x_new-this._x);
if ((dx>speed) || (dx<-speed)) {

this._x += sign_x*speed;
} else {
x_new = Math.random()*width;
}

}

Any suggestions? Thanks.[/quote]

To alter the speed of an alpha tween, the easiest way would be to use the Tween class (or a similar tween engine) and apply a random value to the duration. For greater control over the speed, set the useSeconds parameter of the tween to false and apply a random duration that’s appropriate to your movie’s frame rate.

if you are just changing the location of the movieclip and then doing random _alpha fades there is no point to remove the movie clip then re copy it that is a waste of time just fade it out then move it the turn the alpha back on

using the tween classes would be best for this

First of all, I appreciate the replies thus far. I happy to receive the attention. To better illustrate my needs, below is a web site with the effect I am trying to mimic, but with a different shape scheme and color variability; if you have ever seen the introduction to Thomas Crown Affair then you will know what I am talking about. I drew inspiration from this site’s use of the _alpha fade in/fade out scheme as well as the random orchestration of its mcs. In fact, Ive sat and stared at this site for quite some time now and have realized all the mc’s instances of size, placement, alpha and duration of each of the objects are quite random.

I think Ive come fairly close with the code so far but I am trying to figure out how to introduce the objects with 0% alpha and give them a peak at 100% and then a fade out to 0% and remove them and replace them when they fade out again with an all new object of random size, speed etc… Id like to replace them simply for the fact that no new shapes or sizes will be introduced with a fixed amount given by “i = 0; while (i<9)”. Each mc rebounds and reverses direction when it hits the constraints of the movie clip set at 1024 x 768 and adds nothing new to the mix…so Id like to see a new one added in and an old one removed when it has passed through its alpha cycle: ergo the _alpha 0% -> 100% -> 0%. But rather than get too heady with the description take a look at the following link:

http://www.reschio.com/enter.html

Again, I thank you all for your thoughts.