Following Weyerts suggestion to update all stars in 1 onEnterFrame.. Here is
a little demo (150 stars): http://www.debit.nl/flashcoders/stars.html
This is the code, just place it in the first frame and make a MovieClip and
export it for AS with the name "star"
var starCount:Number = 150;
var stars:Array = new Array();
var alphaSpeed:Number = 5;
for(var a:Number = 0 ; a<starCount ; a++){
var tmpStar:MovieClip =
this.attachMovie("star","star"+a,this.getNextHighestDepth());
tmpStar._x = Math.random() * Stage.width;
tmpStar._y = Math.random() * Stage.height;
tmpStar.alphaSpeed = (Math.random()>0.5?1:-1) * ((Math.random() *
alphaSpeed) + 1);
stars.push(tmpStar);
}
onEnterFrame = function(){
var i:Number = 0;
while(i<starCount){
stars[i]._alpha += stars[i].alphaSpeed;
if(stars[i]._alpha <= 0){
stars[i]._alpha = 0;
stars[i].alphaSpeed *= -1;
}
if(stars[i]._alpha >= 100){
stars[i]._alpha = 100;
stars[i].alphaSpeed *= -1;
}
i++;
}
}
Greetz,
Bernard
> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Namens
> Marcelo de Moraes Serpa
> Verzonden: maandag 3 juli 2006 21:11
> Aan: Flashcoders mailing list
> Onderwerp: Re: [Flashcoders] 50 stars blinking... app gets too slow
>
> Hmmm... looking better at this loop, I don´t think it would
> do the smooth fade-in/fade-out I would like to achieve. I
> guess the best solution still is animating this
> fade-in/fade-out using the flash IDE and then do a play() in
> the script. I would have only to add a line of script in the
> last keyframe of the star animation to make it loop.
>
> On 7/3/06, Marcelo de Moraes Serpa <[EMAIL PROTECTED]> wrote:
> >
> > Ok Weyert...:) now I think I´ve got the point - each star
> would have a
> > different speed, so, they would blink at different time
> rates, right?
> > And with only one loop to achieve this, I would prevent myself of
> > attaching an onEnterFrame to each of the stars...
> >
> > Marcelo.
> >
> >
> > On 7/3/06, Weyert de Boer <[EMAIL PROTECTED]> wrote:
> > >
> > > Well, what you do is you add +5 or -5 to the current _alpha value.
> > > Meaning you will increase or decrease the current alpha
> value by 5.
> > > It's like writing instance._alpha = instance._alpha - 5
> (or + 5). Of
> > > course, you can use some sort of loop to update all
> movieclips/stars i.e:
> > >
> > > var starsCount = 50;
> > > var i =0;
> > > while ( i < starsCount ) {
> > > var currentStar = _root[ "star" + i ]._alpha ;
> > > currentStar._alpha = currenStar._alpha + currentStar.alphaSpeed;
> > > i++;
> > > }
> > > _______________________________________________
> > > [email protected]
> > > To change your subscription options or search the archive:
> > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> > >
> > > Brought to you by Fig Leaf Software
> > > Premier Authorized Adobe Consulting and Training
> > > http://www.figleaf.com http://training.figleaf.com
> > >
> >
> >
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com http://training.figleaf.com
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com