Arrays how to or common functions:

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.

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:


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…:slight_smile:

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

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:


<?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:


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.

Here’s my way to skin a cat…
Requires actionscript 3.0 and [COLOR=“Blue”][U]TweenMax[/U][/COLOR].
[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]

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;
	}
}

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 :slight_smile: