PDA

View Full Version : fmx - arg! attaching dynamic scripts don't work!



davetamzin
August 6th, 2003, 09:00 AM
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! :)


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!

Johnny64
August 6th, 2003, 09:37 AM
Here ;)

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[i].SavedNum = i;//saves i as SavedNum
buttons_array[i].onRollOver = function() {
_root.infoBox_txt.text = _root.info_array[SavedNum];//adds text for the info_array to a TextField
};
buttons_array[i].onRollOut = function() {
_root.infoBox_txt.text = ".........";// clears the textField
};
buttons_array[i].onPress = function() {
_root.gotoAndPlay(SavedNum);// goto and plays to a frame
};
}


and now you can add any thing you like ;)
i have added something for the example

davetamzin
August 6th, 2003, 10:28 AM
one thing....

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

:)