Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 06-10-2004, 11:45   #1 (permalink)
Neuer User
 
Registriert seit: Aug 2001
Beiträge: 5
AS-Code mehrfach verwenden

Hallo,

ich würde gern AS-Code, der für ca. 70 MCs exakt gleich ist, erst zur Laufzeit in diese MCs kopieren. Der Code sieht so aus:
ActionScript:
  1. this.onRollOver = function () {
  2.  _root.set_colors_back();
  3.  _root.highlight_country(this._name);
  4. };
  5. this.onRollOut = function () {
  6.  _root.karte.country.removeMovieClip();
  7. };
  8. this.onMouseMove = function () {
  9.  _root.karte.country._x=_root.karte._xmouse+5;
  10.  _root.karte.country._y=_root.karte._ymouse-5;
  11. };
  12. this.onPress = function () {
  13.  _root.set_colors_back_bypress();
  14.  _root.highlight_country_bypress(this._name);
  15.  _root.setstatusback();
  16. };

Wie ihr seht, werden dort einfach ein paar Funktionen aufgerufen.

Meine Frage ist also: Wie kann man, ohne #include, diesen Code in den ersten Frame der MCs, sagen wir in einer Schleife, schreiben.

Vielen Dank für jeden Tipp

tin
tintinabuli ist offline   Mit Zitat antworten
Alt 06-10-2004, 11:54   #2 (permalink)
alien
 
Benutzerbild von Smirgel
 
Registriert seit: May 2002
Ort: Colonia
Beiträge: 7.597
moin.
ActionScript:
  1. for(i=0;i<70;i++){
  2.  this["mc"+i].onRollOver = function () {
  3.   _root.set_colors_back();
  4.   _root.highlight_country(this._name);
  5.  };
  6.  this["mc"+i].onRollOut = function () {
  7.   _root.karte.country.removeMovieClip();
  8.  };
  9.  this["mc"+i].onMouseMove = function () {
  10.   _root.karte.country._x=_root.karte._xmouse+5;
  11.   _root.karte.country._y=_root.karte._ymouse-5;
  12.  };
  13.  this["mc"+i].onPress = function () {
  14.   _root.set_colors_back_bypress();
  15.   _root.highlight_country_bypress(this._name);
  16.   _root.setstatusback();
  17.  };
  18. }

grüße.
smirgel.
__________________
bei fragen, fragen.
Smirgel ist offline   Mit Zitat antworten
Alt 06-10-2004, 12:07   #3 (permalink)
Neuer User
 
Registriert seit: Aug 2001
Beiträge: 5
Vielen Dank, klappt aber noch nicht. Sicher sind meine Pfadangaben falsch!?

So habe ich das nun (die MC-Namen liegen in einem Array):
ActionScript:
  1. for(i=0;i<a_laender.length;i++) {
  2.  this[_root.karte.laender_hls[a_laender[i]]].onRollOver = function () {
  3.   _root.set_colors_back();
  4.   _root.highlight_country(this._name);
  5.  };
  6.  this[_root.karte.laender_hls[a_laender[i]]].onRollOut = function () {
  7.   _root.karte.country.removeMovieClip();
  8.  };
  9.  this[_root.karte.laender_hls[a_laender[i]]].onMouseMove = function () {
  10.   _root.karte.country._x=_root.karte._xmouse+5;
  11.   _root.karte.country._y=_root.karte._ymouse-5;
  12.  };
  13.  this[_root.karte.laender_hls[a_laender[i]]].onPress = function () {
  14.   _root.set_colors_back_bypress();
  15.   _root.highlight_country_bypress(this._name);
  16.   _root.setstatusback();
  17.  };
  18. };

Ach so, ein Beispiel für einen Pfad:
_root.karte.laender_hls[a_laender[i]] = _root.karte.laender_hls.is (is steht für Island)

tin

Geändert von tintinabuli (06-10-2004 um 12:35 Uhr)
tintinabuli ist offline   Mit Zitat antworten
Alt 06-10-2004, 12:48   #4 (permalink)
Neuer User
 
Registriert seit: Aug 2001
Beiträge: 5
Unsinn! Denkfehler. Das "this" hat mich verwirrt.

Vielen Dank für deine Hilfe!!!

Der Vollständigkeit halber: So ist es richtig:

ActionScript:
  1. for(i=0;i<a_laender.length;i++) {
  2.  _root.karte.laender_hls[a_laender[i]].onRollOver = function () {
  3.    _root.set_colors_back();
  4.    _root.highlight_country(this._name);
  5.  };
  6.  _root.karte.laender_hls[a_laender[i]].onRollOut = function () {
  7.    _root.karte.country.removeMovieClip();
  8.  };
  9.  _root.karte.laender_hls[a_laender[i]].onMouseMove = function () {
  10.    _root.karte.country._x=_root.karte._xmouse+5;
  11.    _root.karte.country._y=_root.karte._ymouse-5;
  12.  };
  13.  _root.karte.laender_hls[a_laender[i]].onPress = function () {
  14.    _root.set_colors_back_bypress();
  15.    _root.highlight_country_bypress(this._name);
  16.    _root.setstatusback();
  17.  };
  18. };
tintinabuli ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 23:29 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele