sr4136
04-12-2008, 11:01 PM
Hi. I'm trying to do an assignment, and I can't seem to figure out how to get the last part. Here are the directions:
"Using a for loop, fill the array with 10 rectangles. Then using forEach, change the alpha value of each rectangle so that the rectangle on the left is solid and the last rectangle on the right is transparent"
Here is what I have:
public function forEachArray():void {
var flArray2:Array = new Array();
for (var i:int=0; i<10; i++) {
var xpos:int = 30 + (i*30);
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xff0000);
mySprite.graphics.lineStyle(1);
mySprite.graphics.drawRect(xpos, 30, 30, 85);
mySprite.graphics.endFill();
addChild(mySprite);
flArray2.push(mySprite);
}
function arrayAlpha(element:Sprite, index:int, a:Array):void {
element.alpha = (index*.25);
}
flArray2.forEach(arrayAlpha);
}
Yes, it must be done in this ridiculous way, and all I have left to do is make it solid on the left, fading to transparent. I have it opposite. Any help please?
"Using a for loop, fill the array with 10 rectangles. Then using forEach, change the alpha value of each rectangle so that the rectangle on the left is solid and the last rectangle on the right is transparent"
Here is what I have:
public function forEachArray():void {
var flArray2:Array = new Array();
for (var i:int=0; i<10; i++) {
var xpos:int = 30 + (i*30);
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xff0000);
mySprite.graphics.lineStyle(1);
mySprite.graphics.drawRect(xpos, 30, 30, 85);
mySprite.graphics.endFill();
addChild(mySprite);
flArray2.push(mySprite);
}
function arrayAlpha(element:Sprite, index:int, a:Array):void {
element.alpha = (index*.25);
}
flArray2.forEach(arrayAlpha);
}
Yes, it must be done in this ridiculous way, and all I have left to do is make it solid on the left, fading to transparent. I have it opposite. Any help please?