PDA

View Full Version : Same action for all



JeffBrazil
November 12th, 2004, 10:38 AM
Hi,

I have an actionscript that controls the movieclips _alpha through instance names. The problem is: I habe a lot of movieClips and I will use the same action in all of them. The same action, just changing the instance name.
Is there a way to put them (instance name) all together in just one as??

Thanxs
Jefferson :whistle:

GreenLantern
November 12th, 2004, 10:54 AM
Post the code you are using, i'll see if I can help you modify it.

icio
November 12th, 2004, 12:35 PM
take a look at prototypes:
http://www.kirupa.com/developer/oop/AS1OOPClassesWithMCs2.htm

JeffBrazil
November 12th, 2004, 12:45 PM
Post the code you are using, i'll see if I can help you modify it.

Hope you don´t get frightened :thumb: here it is the code:

//Médio Paraíba III
mp3.onRelease = function() {
loadMovieNum("medioparaibaIII.swf", "2");
_parent.mapa.unloadMovie();
};
mp3.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
_root.createTextField("regiao");
regiao.text = "Médio Paraíba III";
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
mp3.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
_root.createTextField("regiao");
regiao.text = "";
trace("aumentando");
}
};
};
//-----------------------------X---------------------------
//Médio Paraíba II
mp2.onRelease = function() {
loadMovieNum("medioparaibaII.swf", "2");
_parent.mapa.unloadMovie();
};
mp2.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
_root.createTextField("regiao");
regiao.text = "Médio Paraíba II";
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
mp2.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
_root.removeTextField("regiao");
regiao.text = "";
trace("aumentando");
}
};
};
//-----------------------------X---------------------------
//Baía de Ilha Grande
big.onRelease = function() {
loadMovieNum("big.swf", "2");
_parent.mapa.unloadMovie();
};
big.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
big.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
trace("aumentando");
}
};
};
//-----------------------------X--------------------------
//Médio ParaíbaI
mp1.onRelease = function() {
loadMovieNum("medioparaibaI.swf", "2");
_parent.mapa.unloadMovie();
};
mp1.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
mp1.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
trace("aumentando");
}
};
};
//-----------------------------X--------------------------
//Metropolitana I
m1.onRelease = function() {
loadMovieNum("metropolitanaI.swf", "2");
_parent.mapa.unloadMovie();
};
m1.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
m1.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
trace("aumentando");
}
};
};
//-----------------------------X--------------------------
//Metropolitana II
m2.onRelease = function() {
loadMovieNum("metropolitanaII.swf", "2");
_parent.mapa.unloadMovie();
};
m2.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
m2.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
trace("aumentando");
}
};
};
//-----------------------------X--------------------------
... and goes on

Also hope you can help me or tell me that´s the way it is.....

Thanxs once more,
Jefferson

stringy
November 12th, 2004, 01:38 PM
Hope you don´t get frightened :thumb: here it is the code:

//Médio Paraíba III
mp3.onRelease = function() {
loadMovieNum("medioparaibaIII.swf", "2");
_parent.mapa.unloadMovie();
};
mp3.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
_root.createTextField("regiao");
regiao.text = "Médio Paraíba III";
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
mp3.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
_root.createTextField("regiao");
regiao.text = "";
trace("aumentando");
}
};
};
//-----------------------------X---------------------------
//Médio Paraíba II
mp2.onRelease = function() {
loadMovieNum("medioparaibaII.swf", "2");
_parent.mapa.unloadMovie();
};
mp2.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
_root.createTextField("regiao");
regiao.text = "Médio Paraíba II";
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
mp2.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
_root.removeTextField("regiao");
regiao.text = "";
trace("aumentando");
}
};
};
//-----------------------------X---------------------------
//Baía de Ilha Grande
big.onRelease = function() {
loadMovieNum("big.swf", "2");
_parent.mapa.unloadMovie();
};
big.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
big.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
trace("aumentando");
}
};
};
//-----------------------------X--------------------------
//Médio ParaíbaI
mp1.onRelease = function() {
loadMovieNum("medioparaibaI.swf", "2");
_parent.mapa.unloadMovie();
};
mp1.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
mp1.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
trace("aumentando");
}
};
};
//-----------------------------X--------------------------
//Metropolitana I
m1.onRelease = function() {
loadMovieNum("metropolitanaI.swf", "2");
_parent.mapa.unloadMovie();
};
m1.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
m1.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
trace("aumentando");
}
};
};
//-----------------------------X--------------------------
//Metropolitana II
m2.onRelease = function() {
loadMovieNum("metropolitanaII.swf", "2");
_parent.mapa.unloadMovie();
};
m2.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
trace("diminuindo");
} else {
delete this.onEnterFrame;
}
};
};
m2.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
trace("aumentando");
}
};
};
//-----------------------------X--------------------------
... and goes on

Also hope you can help me or tell me that´s the way it is.....

Thanxs once more,
Jefferson

I`ve just done a little of this for you (mp1,mp2,mp3) -obviously untested but shouldn`t be too far away.

I hope it gives you some ideas on how to do the rest.

myArray = ["medioparaibaI.swf", "medioparaibaII.swf", "medioparaibaIII.swf"];
myArray1 = ["Médio Paraíba I", "Médio Paraíba II", "Médio Paraíba III"];
for (var i = 1; i<4; i++) {
clip = this["mp"+i];
clip.ivar = i-1;
clip.onRelease = function() {
loadMovieNum(myArray[this.ivar], "2");
_parent.mapa.unloadMovie();
};
clip.onRollOver = function() {
this.onEnterFrame = function() {
if (this._alpha>=50) {
this._alpha -= 4;
//parameters for textfield?
_root.createTextField("regiao")
regiao.text = myArray1[this.ivar];
} else {
delete this.onEnterFrame;
}
};
};
clip.onRollOut = function() {
this.onEnterFrame = function() {
if (this._alpha<=100) {
this._alpha += 4;
regiao.text = "";
}
};
};
}

other things you could do is as suggested above so you only have to type your functions once(accepting different arguements.)
You could put other clips into arrays and loop through the arrays etc.