# Using a loop to dynamically alter items

**URL:** <https://forum.kirupa.com/t/using-a-loop-to-dynamically-alter-items/283420>\
**Category:** Uncategorized\
**Created:** [March 5, 2009, 9:45pm UTC](https://forum.kirupa.com/t/using-a-loop-to-dynamically-alter-items/283420 "2009-03-05T21:45:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![darngooddesign](https://avatars.discourse-cdn.com/v4/letter/d/d26b3c/32.png) [@darngooddesign](https://forum.kirupa.com/u/darngooddesign)\
**Post date:** [March 5, 2009, 9:45pm UTC](https://forum.kirupa.com/t/using-a-loop-to-dynamically-alter-items/283420/1 "2009-03-05T21:45:10Z")

</div>

Basically I have five mcs on the stage, MC1, MC2, MC3, MC4, MC5, and I would like to change the alpha, for example, each time I click on [COLOR=Blue]nextBtn[/COLOR]. I would control the number of mcs but altering the [COLOR=Blue]if (j \<= 4){[/COLOR] line.

var myArray:Array = [“mc”];  
var j:int = 1;  
nextBtn.addEventListener(MouseEvent.CLICK, onNext);  
function onNext(evt:MouseEvent):void {  
for (var i:String in myArray){  
trace((myArray\*) + j);  
((myArray\*) + j).alpha = .5;  
if (j \<= 4){  
j = j + 1;  
} else {  
j = 5;  
}  
}  
}

[COLOR=Blue]trace((myArray\*) + j);[/COLOR] works just fine, but as soon as I try to do something tangible with it, [COLOR=Blue]((myArray\*) + j).alpha = .5;[/COLOR], I get the following error:

[COLOR=Blue]ReferenceError: Error #1056: Cannot create property alpha on String.  
at Timeline\_Test\_fla::MainTimeline/onNext()  
[/COLOR]
