# Arrays how to or common functions:

**URL:** https://forum.kirupa.com/t/arrays-how-to-or-common-functions/260318
**Category:** Uncategorized
**Created:** [May 14, 2008, 12:59pm UTC](https://forum.kirupa.com/t/arrays-how-to-or-common-functions/260318 "2008-05-14T12:59:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dunger99us](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dunger99us](https://forum.kirupa.com/u/dunger99us)
#### Post date: [May 14, 2008, 12:59pm UTC](https://forum.kirupa.com/t/arrays-how-to-or-common-functions/260318/1 "2008-05-14T12:59:39Z")

</div>

hi, all,

I need some help here:

lets say i have world map, with 230 countries maps(movieclips), I would like to create a common function using an array for all of these so that I do not have to add for each and every country’s movie clipa line of the code.

what do I mean by that?  
look at this code for example, applied to 1 movieclip named “argentina”:  
I am improting Dropshadow filter, and then—apply rollOut function.

```auto
import flash.filters.DropShadowFilter;
argentina.onRollOver= function() {
 var filter:DropShadowFilter = new DropShadowFilter(5, 5, 0x000000, 0.8,5, 5, 1, 3, false, false, false);
 var filterArray:Array = new Array();
 filterArray.push(filter);
 this.filters = filterArray;
 txtfield.text = "ARGENTINA";
 txtcapital.text ="Capital: Buenos Aires";
 mc_loader.contentPath = "flags/flag_argentina.png";
 this._alpha=75;
 } 
 argentina.onRollOut = function() {
    argentina.filters=null;
 txtfield.text = "";
 txtcapital.text ="";
 mc_loader.contentPath = "";
 this._alpha=100;
} 

```

what I would like to have is: something lioke the code below:

```auto

var country list : argentina, brasil, uruguay etc.
var capitals: buenos aires, brasilia,montevideo, etc
var flags: argentina.jpg, brasil.jpg, uruguay.jpg etc.jpg

```

and I am iam getting lost in here:

I would like to have a movie clip when it has been “mousedover” to change its alpha to 75%,display the name of the country in the dynamic textfield, dysplay its capital in another textfield, and diplay a flag picture in the loader component — and on RollOut event CLEAR all text and loader fields and return alpha to its original state **all USING ARRAYS.**

**If you look at my code: I have accomplished it all, but for each individual movie clip.**

**what I would like to have is a function which will be applied to all movie clips with similar letter sequences, like map\_argentina, map\_brasil, map\_uruguay and similalrly to the dynamic textfields.**

**can someone PLEASE help???**

**otherwise it is very tedious job for 290 countries, you know…🙂**

---

<div class="post-metadata">

### Author: ![dunger99us](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dunger99us](https://forum.kirupa.com/u/dunger99us)
#### Post date: [May 14, 2008, 5:01pm UTC](https://forum.kirupa.com/t/arrays-how-to-or-common-functions/260318/2 "2008-05-14T17:01:27Z")

</div>

basically I need a line of code that will use array of countries, capitals, flags and depending on the movie clips name will display it approprietly

---

<div class="post-metadata">

### Author: ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)
#### Post date: [May 14, 2008, 5:45pm UTC](https://forum.kirupa.com/t/arrays-how-to-or-common-functions/260318/3 "2008-05-14T17:45:19Z")

</div>

I would probably pull the names out of an XML file into an XMLList, and then create buttons based on the length of the array:

```auto

<?xml version="1.0" encoding="utf-8" ?>
<data>
	<country>
		<name>Argentina</name>
		<capital>Buenos Aires</capital>
		<flag>flags/aregnflag.jpg</flag>
	</country>
	<country>
		<name>Brasil</name>
		<capital>Brasilia</capital>
		<flag>flags/brasilflag.jpg</flag>
	</country>
</data>

```

Once you’ve got that XML data loaded, put the data into XMLLists:

```auto

var countryList:XMLList = xml.country.name;
var capitalList:XMLList = xml.country.capitol;
var flagList:XMLList = xml.country.flag;

for(var z:int = 0; z < countries.length; z++)
{
     createButton(countryList[z], capitalList[z], flagList[z]);
}

function createButton(name:String, capital:String, flag:String):void
{
     setTitleText(name);
     setCapital(capital);
     loadFlag(flag);
}

```

So that’s the general logic I think you should go for.

---

<div class="post-metadata">

### Author: ![snickelfritz](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@snickelfritz](https://forum.kirupa.com/u/snickelfritz)
#### Post date: [May 14, 2008, 10:48pm UTC](https://forum.kirupa.com/t/arrays-how-to-or-common-functions/260318/4 "2008-05-14T22:48:28Z")

</div>

Here’s my way to skin a cat…  
Requires actionscript 3.0 and [[COLOR=“Blue”][U]TweenMax[/U][/COLOR]](http://blog.greensock.com/tweenmaxas3/).  
[LIST=1]  
[_]Create movieclips for each state, instance names “state1”, “state2” etc…  
[_]Wrap the state movieclips in a movieclip, instance name “stateGroup”  
[_]Create 2 dynamic text fields “stateTxt” and “capitolTxt”  
[_]Create the flags in Photoshop using the stack script and save it as a layered psd.  
[_]import the flag.psd into Flash as a layered file.  
[_]Choose “distribute layers to keyframes”.  
[_]Select all layers and set the compression, and choose to create movieclips for each of the flags.  
[_]Create a set of frameLabels that match the state movieclip instance names, and that correspond to the flag image keyframes.  
ie: flag that represents “state1” is located at frameLabel “state1”, etc…  
[/LIST]  
[[COLOR=“Blue”][U]Functional Example[/U][/COLOR]](http://www.byrographics.com/AS3/stateCapitol/states_capitols.swf)

```auto
stop();
import gs.TweenMax;
import fl.motion.easing.*;
stage.scaleMode = StageScaleMode.NO_SCALE;
var stateName:String = "";

stateGroup.buttonMode = true;
stateGroup.mouseEnabled = true;
stateGroup.addEventListener(MouseEvent.MOUSE_OVER , rollover, false, 0, true);
stateGroup.addEventListener(MouseEvent.MOUSE_OUT, rollout, false, 0, true);

function rollout(event:MouseEvent):void {
	TweenMax.to(event.target, .5, {scaleX:1, scaleY:1, dropShadowFilter:{color:0x000000, alpha:0, blurX:0, blurY:0, strength:1, angle:45, distance:0}});
	stateTxt.text = "State";
	capitolTxt.text = "State Capitol";
	gotoAndStop(1);
}

function rollover(event:MouseEvent):void {
	stateName = event.target.name;
	gotoAndStop(stateName);
	trace(stateName);
	TweenMax.to(event.target, .5, {scaleX:1.02, scaleY:1.02, dropShadowFilter:{color:0x000000, alpha:0.5, blurX:5, blurY:5, strength:1, angle:45, distance:5}});
	switch (stateName) {
		case "state1" :
			stateTxt.text = "Arizona";
			capitolTxt.text = "Phoenix";
			break;
		case "state2" :
			stateTxt.text = "Colorado";
			capitolTxt.text = "Denver";
			break;
		case "state3" :
			stateTxt.text = "California";
			capitolTxt.text = "Sacramento";
			break;
		case "state4" :
			stateTxt.text = "Utah";
			capitolTxt.text = "Salt Lake City";
			break;
		case "state5" :
			stateTxt.text = "Wyoming";
			capitolTxt.text = "Cheyenne";
			break;
	}
}

```

---

<div class="post-metadata">

### Author: ![Vampyre](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@Vampyre](https://forum.kirupa.com/u/Vampyre)
#### Post date: [May 15, 2008, 11:21pm UTC](https://forum.kirupa.com/t/arrays-how-to-or-common-functions/260318/5 "2008-05-15T23:21:45Z")

</div>

Hey guys, I thought I’ll post here since it’s of similar topic.

I have a couple of MCs stored in an array and rollover, rollout commands all work fine on them. But what’s the way to have commands like .\_x, .\_alpha to properly affect the MCs in arrays? I tried and it doesn’t work.

var diaryMenu:Array = [“DiaryY2007\_mc”, “DiaryY2008\_mc”, “DiaryM01\_mc”, “DiaryM02\_mc”];  
for (i = 0; i \< diaryMenu.length; i++) {  
this[diaryMenu\*].onRollOver = function() {  
this.gotoAndStop(“Selected”);  
}  
};  
for (i = 0; i \< diaryMenu.length; i++) {  
this[diaryMenu\*].onRollOut = function() {  
this.gotoAndStop(“Normal”);  
}  
};

Diary\_btn.onRelease = function() {  
for (i = 0; i \< diaryMenu.length; i++) {  
this[diaryMenu\*].\_x = 100;  
this[diaryMenu\*].\_alpha = 100;  
}  
};

Once again, the mouse commands work fine, but .\_x and .\_alpha are not working.

Help help 🙂
