Zurück   Flashforum > Flash > Stuff

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 14-12-2003, 14:30   #1 (permalink)
stop the fog
 
Benutzerbild von < priZma >
 
Registriert seit: Apr 2003
Beiträge: 97
[stuff] setClipInFreeLevel

Da ich öfters mit MovieClip Level setzen probleme habe habe ich mir eine simple Lösung überlegt, die das
zumindest bei createEmptyMovieClip umgeht.
Da ich hier im Forum noch nichts ähnliches gefunden habe poste ich mal den prototype.

Vieleicht kann ihn der ein oder andere ja gebrauchen.
ActionScript:
  1. MovieClip.prototype.setClipInFreeLevel = function (name) {
  2.     this.level = 0;
  3.     for (var info in this) {
  4.         if (typeof this[info] == "movieclip") {
  5.             this.level++;
  6.         }
  7.     }
  8.     this.createEmptyMovieClip (name, this.level + 1);
  9. };
  10.  
  11. // Test
  12. this.setClipInFreeLevel ("a");
  13. this.setClipInFreeLevel ("b");
  14. this.setClipInFreeLevel ("c");
  15. this.setClipInFreeLevel ("d");
  16. this.setClipInFreeLevel ("e");
  17. this.setClipInFreeLevel ("f");
  18. this.setClipInFreeLevel ("g");
  19. this.setClipInFreeLevel ("h");
  20. //
  21. for (var info in this) {
  22.     if (typeof this[info] == "movieclip") {
  23.         trace (this[info]);
  24.     }
  25. }

schönen Sonntag noch.
.priZma
< priZma > ist offline   Mit Zitat antworten
Alt 14-12-2003, 19:53   #2 (permalink)
Coalado
 
Registriert seit: Jun 2001
Ort: Lagcity.de
Beiträge: 683
hm...


ActionScript:
  1. MovieClip.prototype.setClipInFreeLevel = function (name) {
  2.         this.level = 0;
  3.         for (var info in this) {
  4.                 if (typeof this[info] == "movieclip") {
  5.                         this.level++;
  6.                 }
  7.         }
  8.         this.createEmptyMovieClip (name, this.level + 1);
  9. };
  10.  
  11. // Test
  12. this.setClipInFreeLevel ("a");
  13. this.setClipInFreeLevel ("b");
  14. this.setClipInFreeLevel ("c");
  15. this.setClipInFreeLevel ("d");
  16. this.setClipInFreeLevel ("e");
  17. //!!!!
  18. this.c.removeMovieClip()
  19.  
  20. //
  21. this.setClipInFreeLevel ("f");
  22. this.setClipInFreeLevel ("g");
  23. this.setClipInFreeLevel ("h");
  24. //
  25.  
  26.  
  27. for (var info in this) {
  28.         if (typeof this[info] == "movieclip") {
  29.                 trace (this[info]);
  30.         }
  31. }



Probier das mal aus.


du zählst die anzahl von MovieClips. du vergisst dabei, aber 2 wichtige dinge..

1. behält ein MovieClip seine Tiefe, auch wenn ein Mc vor ihm gelöscht wird,
seine tiefe kann nur per swapDepths geändert werden.


2. Die Tiefe von den MovieClips muss nicht vortlaufend sein...


das heißt wenn du auf

1,2,3,4,5 die mcs a,b,c,d,e liegen hast, und du löscht c, dann liegen a,b,d,e, auf 1,2,4,5 und nicht auf 1,2,3,4


das heißt dass dein script dem nächsten MOvieClip die tiefe 5 geben wird, und damit den e ersetzen wird.






Hast du dir schon überlegt, bei dem erstellen eines mcs, seine aktuelle tiefe in den neuen mc zu legen, und dann immer nach freien plätzen zu suchen??




ActionScript:
  1. MovieClip.prototype.getLevelList = function() {
  2.     var result = [];
  3.     for (var i in this) {
  4.         if (typeof this[i] == "movieclip") {
  5.             result[this[i].depths] = this[i].depths;
  6.         }
  7.     }
  8.     return result.length == 0 ? [0] : result;
  9. };
  10. MovieClip.prototype.getGap = function(result, startIndex) {
  11.     startIndex = (startindex == null) ? 0 : startIndex;
  12.     var re = false;
  13.     for (var i = startIndex+1; i<result.length; i++) {
  14.         if (result[i] == null) {
  15.             return i;
  16.         }
  17.     }
  18.     return result.pop()+1;
  19. };
  20. var org = MovieClip.prototype.createEmptyMovieClip;
  21. MovieClip.prototype.createEmptyMovieClip = function(name, depths) {
  22.     var result = arguments.callee.org.apply(this, arguments);
  23.     result.depths = depths;
  24.     return result;
  25. };
  26. MovieClip.prototype.createEmptyMovieClip.org = org;
  27. delete org;
  28.  
  29.  
  30. this.createEmptyMovieClip("a", this.getGap(this.getLevelList()));
  31. this.createEmptyMovieClip("b", this.getGap(this.getLevelList()));
  32. this.createEmptyMovieClip("c", this.getGap(this.getLevelList()));
  33. this.createEmptyMovieClip("d", this.getGap(this.getLevelList()));
  34. this.c.removeMovieClip();
  35. this.createEmptyMovieClip("f", this.getGap(this.getLevelList())); // belegt die frei gewordene stelle von c
  36. this.createEmptyMovieClip("g", this.getGap(this.getLevelList()))// ans ende
  37. this.b.removeMovieClip();
  38. this.d.removeMovieClip();
  39. this.createEmptyMovieClip("h", this.getGap(this.getLevelList(),3));//  wird frühestens an stelle 3 angelegt
  40.  




Schnell ist das ganze natürlich nicht
tumetom 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 18:38 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele