basic as3 question
- Started
- Last post
- 3 Responses
- fues
I have a quite basic as3 question. In a for-loop I would like to pass a variable to each movieclip I attach:
for (var i:int=0; i<5; i++) {
var item = navClip.addChild(new asset_navbut());
// now in actionscript 2 I would have done something like this:
item.myX = i*15}
Any ideas how to do this in as3?
Thanks.
- ElectroLAX30000
At a glance it looks like you've forgotten the semi-colon in the line where you pass the variable.
- ElectroLAX30000
Yep I think it's the lack of semi-colon'ness as the following worked fine. I substituted your navClip for an empty sprite and the asset_navbut() method for a textfield constructor and it worked fine.
var navClip:Sprite = new Sprite();
for(var i:int; i<5; i++)
{
var item = navClip.addChild(new TextField);
item.textColor = 0xFF0000;
item.text = "Y HELO THAR" + i;
item.x = i*150;
trace(i);
}this.addChild(navClip);
- sixfngers0
for (var i:int=0; i<5; i++) {
var item = navClip.addChild(new asset_navbut());
item.myX = i*15
item.y = item.myX
item.addEventListener(MouseEvent... clickHandle)}
function clickHandle(evt:Event){
trace(evt.target.myX)
}