Moving Stars Loader – AS3 Tutorial
// February 11th, 2009 // Flash - AS3
OK! This should have been an easy tutorial, but I ended up working on it a lot more than I expected. First…I did not get the effect I wanted (but I got this one and it looks cool…so it is not important). Bust what is important, is that flash runs strange…and I mean really strange sometimes.
It should have been easy: add an ellemet on the stage, make it fade every frame (with 0.1) , if it’s alpha exactly 0.8, add a new element. Simple, right?
The code should have been:
[code lang="actionscript"]
e.currentTarget.alpha-=0.1;
if(e.currentTarget.alpha==0.8){
//code to ad a new element on the stage
}
[/code]
Well…guess what…apparently e.currentTarget.alpha will never be exactly 0.8
Flash does not subtract 0.1 from the alpha of the element…but a strange number…and if we trace the alpha, we will get this:
1
0.8984375
0.796875
0.6953125
0.59375
0.4921875
0.390625
0.2890625
0.1875
0.0859375
So that is why, you will see a strange number in the source code when comparing the alpha of the element to see if we will ad a new one. Don’t know exactly why…this happens…will let you know if I figure it out. You can also try a simple example:
[code lang="actionscript"]
var i:Number;
var n:Number=1;
for (i=0;i<4;i++)
{
n-=0.1;
trace(n)
}
[/code]
And the result:
1
0.9
0.8
0.7000000000000001
0.6000000000000001
Anyway...here is how the loader should work (I think it has already finished loading whyle you read al this...so refresh the page to see the animation);
[kml_flashembed fversion="9.1.0" movie="http://sf-zone.net/wp-content/uploads/2009/02/tutorial1.swf" targetclass="flashmovie" useexpressinstall="true" publishmethod="static" width="400" height="250"]
Leave a Reply
You must be logged in to post a comment.





