Learn flash exercises and randomly generate multiple sprite display elements, pure actionscript3.0 code.
Sprite display element random color, random size
The Code is as follows:
Public Function testcreatesprite (): void
{
For (var I: Int = 0; I <99; I ++)
{
VaR S: SPRITE = new sprite;
S. Name = "hiname _" + I;
VaR color: Int = math. Floor (math. Random () * 0 xffffff); // generate a random color
VaR size: Int = math. Floor (math. Random () * 35); // generate a random size.
S. Graphics. beginfill (color );
S. Graphics. drawcircle (math. Random () * 700 + 10, math. Random () * 600 + 10, size );
S. Graphics. endfill ();
This. addchild (s );
S. addeventlistener (mouseevent. Click, clickhandler );
// S. addeventlistener (mouseevent. mouse_over, overhandler );
}
}
Private function clickhandler (Event: mouseevent): void
{
Trace ("You click:" + event.tar get. Name + "_ typeof:" + typeof event.tar get. Name );
This.removechild(displayobject(event.tar get ));
// Var N: Int = This. Stage. numchildren;
// For (var I: Int = 0; I <n; I ++ ){
// This. Stage. removechildat (I );
//}
// Var mytimer: mytimer = mytimer. getinstance ();
// Mytimer.registertimer(event.tar get. Name, 1, 20, movetoright,event.tar get. Name );
}