This is the 4th Image Rotator I have made so far. I don’t have much description for this one, just experience it yourself!
By the way, some people raised an issue that the images seems blur in Flash when compared to Silverlight. The main reason is because I have set the JPEG quality to 80% when publishing the SWF. The quality may be poor, but in turn of a smaller file size.
Vote for this sample
Comparison
Flash implementation: 40 minutes
Silverlight implementation: 50 minutes (Implemented First)
What’s the difference?
- Rearranging array items randomly [AS3] vs [C#]
Source codes
Random Moving Rotator [Flash 9, AS3] (433.1 KiB, 1,265 hits)
Random Moving Rotator [Silverlight 2, C#] (439.5 KiB, 1,246 hits)
Flash
Silverlight
Rearranging array items randomly [AS3] vs [C#]
Rearranging an array is useful if you want to make some “Fill” effect. In this sample, during each rotation, the program will randomly generate the target position of each grid. This is done by reorganizing the position array.
// AS3
// create an array
var _positions:Array = new Array(50);
for(var i:int = 0; i < _positions.length; i++){
_positions[i] = i;
}
// reposition the array randomly
for(var i:int = 0 ; i < _positions.length; i++){
var targetIndex:int = int(Math.random() * (_positions.length - i)) + i ;
var temp:int = _positions[targetIndex];
_positions[targetIndex] = _positions[i];
_positions[i] = temp;
}
In C#, the code is pretty similiar.
// C#
// create an array
int [] _positions = new int[50];
for (int i = 0; i < _positions.Length; i++)
{
_positions[i] = i;
}
// reposition the array randomly
int seed = (int)DateTime.Now.Ticks;
Random r = new Random(seed);
for (int i = 0; i < _positions.Length - 1; i++)
{
int targetIndex = (int)(r.NextDouble() * (_positions.Length - i)) + i ;
int temp = _positions[targetIndex];
_positions[targetIndex] = _positions[i];
_positions[i] = temp;
}