Fmx - arg! attaching dynamic scripts don't work!

I have a main timeline with a series of buttons, the buttons were created and placed manually, I have a script to attach the code to the buttons, but iI can’t get it to work! GRRRR!

I would really appreciate some pointers, pretty please! :slight_smile:

for(i=0;i<menu_array.length;i++){

["mentext" +i].onRelase = function(){
_global.menusel = i;
if (_global.mensel>_global.maxmenu){
_global.maxmenu=_global.menusel;
}
_level1.play();
change();
}
}

How do I get code like this (ie a function, onto the buttons at run time, I’ve tried several different ways (including verbally abusing my pc, which normally works) to no avail…

Please help!

Here :wink:

one thing…
the i var the is made by the for loop you can’t use it for you functions because the function is run then the for loop has finished and the i var is deleted. So if you what to use the i var you will have to save it…


buttons_array = [home_btn, info_btn, contact_btn];//put your button naans in an array
info_array = ["This is our home page", "Here is some info about us", "You can contact us here"];// you can put other info in other arrays
for (i=0; buttons_array.length>i; i++) {
	buttons_array*.SavedNum = i;//saves i as SavedNum
	buttons_array*.onRollOver = function() {
		_root.infoBox_txt.text = _root.info_array[SavedNum];//adds text for the info_array to a TextField 
	};
	buttons_array*.onRollOut = function() {
		_root.infoBox_txt.text = ".........";// clears the textField
	};
	buttons_array*.onPress = function() {
		_root.gotoAndPlay(SavedNum);// goto and plays to a frame
	};
}

and now you can add any thing you like :wink:
i have added something for the example

one thing…

That little snippet is a really useful thing to know! it works like charm now, thank you!

:slight_smile: