Zurück   Flashforum > Flash > ActionScript > Softwarearchitektur und Entwurfsmuster

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 30-08-2003, 08:46   #1 (permalink)
helpQLODhelp
 
Benutzerbild von bokel
 
Registriert seit: Feb 2002
Ort: Köln
Beiträge: 8.505
DesignPattern: Singleton

Unter http://www.onjava.com/pub/a/onjava/2...singleton.html findet ihr einen schönen und leicht verständlichen Artikel über das DesignPattern Singleton. Mögliche Singletonobjekte sind z.B. eine AlertBox, ein Hintergrund-Audioloop oder das Hauptobjekt einer Anwendung.

In AS würde das dann so in der Art aussehen:

ActionScript:
  1. o = _global.AlertBox = function(){
  2. }
  3.  
  4. o.myInstance = null;
  5.  
  6. o.getInstance = function(){
  7.      if( this.myInstance == null){
  8.             this.myInstance = new AlertBox();
  9.      }
  10.      return this.myInstance
  11. }
  12.  
  13. o = o.prototype
  14.  
  15. // hier folgen dann die eigentlichen Methoden der AlertBox.
  16. // ..
  17.  
  18. // Die Benutzung sieht dann etwas so aus:
  19. var ab = AlertBox.getInstance();
  20. ab.show("hallo", "Wichtige Mitteilung");

mfg r.
bokel ist offline   Mit Zitat antworten
Alt 30-08-2003, 10:01   #2 (permalink)
God made me funky..
 
Registriert seit: Apr 2003
Ort: Bremen
Beiträge: 1.067
Da fehlte doch ein this, oder?
ActionScript:
  1. if( this.myInstance == null){
  2.                 this.myInstance = new AlertBox();
  3.         }
  4.         return this.myInstance
__________________
Kunst ist in erster Linie eine Frage der Form und nicht des Inhalts
Paul Rand
e2e4 ist offline   Mit Zitat antworten
Alt 30-08-2003, 10:03   #3 (permalink)
helpQLODhelp
 
Benutzerbild von bokel
 
Registriert seit: Feb 2002
Ort: Köln
Beiträge: 8.505
Ja, ich habe es ergänzt,
danke für den Hinweis,
mfg r.
bokel 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 12:58 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele