# \[AS2\] Creating functions and their contents dynamicly

**URL:** <https://forum.kirupa.com/t/as2-creating-functions-and-their-contents-dynamicly/268306>\
**Category:** flash\
**Created:** [August 12, 2008, 1:53pm UTC](https://forum.kirupa.com/t/as2-creating-functions-and-their-contents-dynamicly/268306 "2008-08-12T13:53:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![goSTE](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@goSTE](https://forum.kirupa.com/u/goSTE)\
**Post date:** [August 12, 2008, 1:53pm UTC](https://forum.kirupa.com/t/as2-creating-functions-and-their-contents-dynamicly/268306/1 "2008-08-12T13:53:51Z")

</div>

Hi there,

Thanks a lot for taking the time to try to help me!

Here’s my problem;

I have a lot of countries, and i want to make functions for each country, here’s working code.

united\_kingdom.onRollOver = function() {  
animateCountry(“united\_kingdom”)  
}  
algeria.onRollOver = function() {  
animateCountry(“algeria”)  
}  
australia.onRollOver = function() {  
animateCountry(“australia”)  
}

This works fine, but with a huge list of countries and needing to do rollOut and press etc, i’d like to make the function creation dynamic so i’ve tried…  
var countryList = new Array ()  
countryList[0]=“united\_kingdom”  
countryList[1]=“algeria”  
countryList[2]="australia

for (j=0;j\<countryList.length;j++) {  
// set the countrys roll over state  
this[countryList[j]].onRollOver = function() {  
animateCountry(countryList[j])  
}  
}

it makes all the correct roll over functions fine, but whenever it executes animateCountry it tries to read countryList[j] rather than taking that literally while the functions made and setting it to the country name.

how do i make it set animateCountry(“united\_kingdom”) inside the function being made?

anyone that can solve this is a genius ofc 😃

many thanks for your help!
