Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 26-08-2005, 15:25   #1 (permalink)
Neuer User
 
Registriert seit: Aug 2003
Ort: Bamberg
Beiträge: 876
Optimieren eines Scriptes

Tag
bin dabei einen slider zu machen inhalte sollen hinteher dyn geladen werden.
wollte fragen ob einer eine idee hat den script zu optimieren da er mir sehr umständlich scheint.
lg
wangman
Angehängte Dateien
Dateityp: zip bsp.zip (7,2 KB, 9x aufgerufen)
wangman ist offline   Mit Zitat antworten
Alt 26-08-2005, 20:59   #2 (permalink)
agedoubleju
Gast
 
Beiträge: n/a
Nun, deine erste drei if-Abfrage könntest du schon stark verkürzen, die fragen ja immer dasselbe ab:
ActionScript:
  1. if (0<_root.mp) {
  2.         _root.pic._x = _root.pic._x+_root.gesch;
  3.         _root.bewegung_r = 1;
  4.         _root.bewegung_l = 0;
  5.     }
  6.         if (0<_root.mp) {
  7.         _root.pic1._x = _root.pic1._x+_root.gesch;
  8.         _root.bewegung_r = 1;
  9.         _root.bewegung_l = 0;
  10.     }
  11.         if (0<_root.mp) {
  12.         _root.pic2._x = _root.pic2._x+_root.gesch;
  13.         _root.bewegung_r = 1;
  14.         _root.bewegung_l = 0;
  15.     }
Daraus könntest du dann bspw. folgendes machen:
ActionScript:
  1. if (0<_root.mp) {
  2. _root.pic._x += _root.gesch;
  3. _root.pic1._x += _root.gesch;
  4. _root.pic2._x += _root.gesch;
  5.         _root.bewegung_r = 1;
  6.         _root.bewegung_l = 0;
  7. }
Oder sollten das else-Zweige sein?
  Mit Zitat antworten
Alt 26-08-2005, 21:16   #3 (permalink)
voidboy
 
Benutzerbild von rendner[i]
 
Registriert seit: Sep 2004
Ort: München
Beiträge: 5.588
Zitat:
Zitat von agedoubleju
Oder sollten das else-Zweige sein?
__________________
ERROR: Signature is too large
rendner[i] ist offline   Mit Zitat antworten
Alt 27-08-2005, 09:59   #4 (permalink)
Neuer User
 
Registriert seit: Aug 2003
Ort: Bamberg
Beiträge: 876
hey
danke für die antwort!!
das problem hab ich jetzt mit funktionen gelöst ich bin eigentlich schon rel weit. aber es gibt nochn paar probleme hier der script :

auf frame 1
ActionScript:
  1. bildanzahl=14
  2. for (var i = 1; i<bildanzahl; i++) {
  3.     _root.createEmptyMovieClip("container"+i, i);
  4.     //_root["container"+i].loadMovie("tod"+i+".jpg");
  5.     _root["container"+i].loadMovie("bild.jpg");
  6.     _root["container"+i]._x = 30;
  7.     _root["container"+i]._y = 80*i;
  8. }
  9. function slide(mcmc) {
  10.     // Position maus
  11.     _root.mp = _ymouse;
  12.     // Bewegung rechts
  13.     if (400<_root.mp) {
  14.         mcmc._y = mcmc._y+_root.gesch;
  15.         _root.bewegung_r = 1;
  16.         _root.bewegung_l = 0;
  17.     }
  18.     // Bewegung links
  19.     if (400>_root.mp) {
  20.         mcmc._y = mcmc._y-_root.gesch;
  21.         _root.bewegung_r = 0;
  22.         _root.bewegung_l = 1;
  23.     }
  24.     // Sprung nach hinten
  25.     if (mcmc._y>=820 && _root.bewegung_r == 1) {
  26.         mcmc._y = -20;
  27.     }
  28.     // Sprung nach vorne
  29.     if (mcmc._y<=-20 && _root.bewegung_l == 1) {
  30.         mcmc._y = 820;
  31.     }
  32.    
  33.     //Geschwindigkeits abfrage und festsetzung links
  34.         if (_root.bewegung_l == 1) {
  35.             if (_ymouse>=400) {
  36.                 _root.gesch = 2.5;
  37.             } else if (_ymouse>=300) {
  38.                 _root.gesch = 5;
  39.             } else if (_ymouse>=200) {
  40.                 _root.gesch = 7.5;
  41.             } else if (_ymouse>=100) {
  42.                 _root.gesch = 10;
  43.             }
  44.         }
  45.          //Geschwindigkeits abfrage und festsetzung rechts
  46.         if (_root.bewegung_r == 1) {
  47.             if (_ymouse<=500) {
  48.                 _root.gesch = 2.5;
  49.             } else if (_ymouse<=600) {
  50.                 _root.gesch = 5;
  51.             } else if (_ymouse<=700) {
  52.                 _root.gesch = 7.5;
  53.             } else if (_ymouse<=800) {
  54.                 _root.gesch = 10;
  55.             }
  56.         }
  57. }


so ich hab das ganze als funktion gemacht, dass ich das ohne probleme und viel script auf viele objekte umlenken kann.

nämlich so:

ActionScript:
  1. onClipEvent (enterFrame) {
  2.         _root.slide(_root.container1);
  3.         _root.slide(_root.container2);
  4.         _root.slide(_root.container3);
  5.         _root.slide(_root.container4);
  6.         _root.slide(_root.container5);
  7.         _root.slide(_root.container6);
  8.         _root.slide(_root.container7);
  9.         _root.slide(_root.container8);
  10.         _root.slide(_root.container9);
  11.         _root.slide(_root.container10);
  12.         _root.slide(_root.container11);
  13.         _root.slide(_root.container12);
  14.         _root.slide(_root.container13);
  15.         _root.slide(_root.container14);
  16. }
geht das einfacher? also ein script, statt das immer wieder zu wiederholen?

und die abstände der bilder sollen gleich bleiben d.h. ich muss das mit der gesch irgendwie ändern .. irgendwelche ideen ?
bis dann
danke nochmal für die antwort dachte schon ich bekomm keine mehr
bis später

wangman

p.s.: nein es waren keine else zweige und es stimmt was du sagst
Angehängte Dateien
Dateityp: zip blabla.zip (7,9 KB, 2x aufgerufen)

Geändert von wangman (27-08-2005 um 10:01 Uhr)
wangman ist offline   Mit Zitat antworten
Alt 27-08-2005, 12:00   #5 (permalink)
Achim Math.PI
 
Benutzerbild von bloba
 
Registriert seit: Jul 2001
Ort: cool Colonia
Beiträge: 11.642
also ich hab gard nur mal kurz drübergschaut und ich denke dass es hier sinnvoll ist mim einem movieclip.prototype zu arbeiten
dh du erstellst eine "funktion" welche du dann auf auf movieclips anwenden kannst.
dann wäre der aufruf nicht mehr
ActionScript:
  1. _root.slide(_root.container1);
  2.  _root.slide(_root.container2);
  3. //...
  4.  
sondern sauber in und kompakt
ActionScript:
  1. for (i=1;i<=anzahl;i++){
  2.  _root["container"+i].slide();
  3. };

wobei du die funktion "slide" eintprechend umändern musst
__________________
gruß bloba

2 x onkel² b_d
bloba ist offline   Mit Zitat antworten
Alt 27-08-2005, 13:12   #6 (permalink)
Neuer User
 
Registriert seit: Aug 2003
Ort: Bamberg
Beiträge: 876
hm und wie änder ich die funktion um ?

ActionScript:
  1. function slide.prototype(mcmc) {
so ?

danke für die hilfe schonmal

lg
wangman
wangman ist offline   Mit Zitat antworten
Alt 27-08-2005, 13:22   #7 (permalink)
tracer
 
Benutzerbild von andretti
 
Registriert seit: Jun 2004
Beiträge: 4.415
aloha!
ActionScript:
  1. MovieClip.prototype.slide = function() {
  2.         // Position maus
  3.         _root.mp = _ymouse;
  4.         // Bewegung rechts
  5.         if (400<_root.mp) {
  6.                 this._y = this._y+_root.gesch;
  7.                 _root.bewegung_r = 1;
  8.                 _root.bewegung_l = 0;
  9.         }
  10.         // Bewegung links
  11.         if (400>_root.mp) {
  12.                 this._y = this._y-_root.gesch;
  13.                 _root.bewegung_r = 0;
  14.                 _root.bewegung_l = 1;
  15.         }
  16.         // Sprung nach hinten
  17.         if (this._y>=820 && _root.bewegung_r == 1) {
  18.                 this._y = -20;
  19.         }
  20.         // Sprung nach vorne
  21.         if (this._y<=-20 && _root.bewegung_l == 1) {
  22.                 this._y = 820;
  23.         }
  24.        
  25.         //Geschwindigkeits abfrage und festsetzung links
  26.         if (_root.bewegung_l == 1) {
  27.                 if (_ymouse>=400) {
  28.                         _root.gesch = 2.5;
  29.                 } else if (_ymouse>=300) {
  30.                         _root.gesch = 5;
  31.                 } else if (_ymouse>=200) {
  32.                         _root.gesch = 7.5;
  33.                 } else if (_ymouse>=100) {
  34.                         _root.gesch = 10;
  35.                 }
  36.         }
  37.         //Geschwindigkeits abfrage und festsetzung rechts
  38.         if (_root.bewegung_r == 1) {
  39.                 if (_ymouse<=500) {
  40.                         _root.gesch = 2.5;
  41.                 } else if (_ymouse<=600) {
  42.                         _root.gesch = 5;
  43.                 } else if (_ymouse<=700) {
  44.                         _root.gesch = 7.5;
  45.                 } else if (_ymouse<=800) {
  46.                         _root.gesch = 10;
  47.                 }
  48.         }
  49. }
  50. //++++++++++++++++++++++++++++++
  51. for (i=1;i<=anzahl;i++){
  52.         _root["container"+i].slide();
  53. };
__________________
Viola per Sempre
Alle Angaben ohne Gewehr!
trace your open mind in variables !
andretti
ActionScript Dictionary
andretti ist offline   Mit Zitat antworten
Alt 27-08-2005, 13:56   #8 (permalink)
Neuer User
 
Registriert seit: Aug 2003
Ort: Bamberg
Beiträge: 876
danke!!
problem 1 wäre damit gelöst
nun zum zweiten problem
probiert mal den film aus dun fahrt rel lange mit der maus rel zügig hoch und runter und guckt was die bildchen machen.
die bewegen sich nämlich von ihrer position weg also der abstand zwischen den bildern bleibt nicht gleich
schauts euch mal an:
Angehängte Dateien
Dateityp: zip Bug.zip (6,4 KB, 3x aufgerufen)
wangman ist offline   Mit Zitat antworten
Alt 27-08-2005, 16:05   #9 (permalink)
tracer
 
Benutzerbild von andretti
 
Registriert seit: Jun 2004
Beiträge: 4.415
probieren ohne bilder?
__________________
Viola per Sempre
Alle Angaben ohne Gewehr!
trace your open mind in variables !
andretti
ActionScript Dictionary
andretti ist offline   Mit Zitat antworten
Alt 27-08-2005, 16:22   #10 (permalink)
Neuer User
 
Registriert seit: Aug 2003
Ort: Bamberg
Beiträge: 876
ups.
ehm so ists besser:
das ganze soll nur n slider werden mit ner voransicht von bildern und wenn man auf ein icon klickt soll es halt das große bild laden samt überschrift und beschreibung. naja bis dahin is es noch n guter weg zumal das dann alles noch auf xml basieren soll, dass ich ohne großen aufstand dinge hinzufügen kann.
Angehängte Dateien
Dateityp: zip Bug.zip (7,4 KB, 12x aufgerufen)

Geändert von wangman (27-08-2005 um 16:31 Uhr)
wangman ist offline   Mit Zitat antworten
Alt 05-12-2005, 15:33   #11 (permalink)
Yi|
Animatöse
 
Registriert seit: Oct 2005
Ort: Berlin
Beiträge: 11
hi,
bist du schon damit fertig? suche genau sowas, fände es super wenn du es hier rein stellen könntest

gruß

Yi
Yi| 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 00:05 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele