Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 07-05-2004, 18:46   #1 (permalink)
Neuer User
 
Benutzerbild von andilab
 
Registriert seit: Jun 2001
Ort: münster
Beiträge: 162
_global.createMessageBox

hallo,

endlich versuch ich mich mal hier zu beteiligen..

..ist kein oop, also schreib ich' hier rein.

- erstellt eine messageBox in _root in der angegebenen tiefe mit n paar buttons und so.. grade fertig geworden, nichts großartiges, aber schnell und einfach eingefügt.

ActionScript:
  1. //aha
  2. /*PARAMETERS
  3. pMsgString - message String
  4. pDepth - depth of messageBox in _root
  5. pBtnObjArray - an array with "button objects"
  6.         example:    [label:"myString",action:myfunction(){...}]
  7.             or
  8.                     [label:"myString",action:"functionName",target:"object where to execute function"]
  9. pX , pY [optional]  - where to create messageBox on stage
  10. */
  11. _global.createMessageBox = function (pMsgString, pDepth, pBtnObjArray,pX,pY) {
  12.     // Main-Mc...
  13.     var mc =_root.createEmptyMovieClip("messageBox_mc", pDepth);
  14.     //maybe usefull..
  15. //  onCreateMessageBox();
  16.     //remove MessageBox-function
  17.     mc.removeMessageBox = function() {
  18.         this.removeMovieClip();
  19. //   onRemoveMessageBox();
  20.     }
  21.  
  22.     //
  23.     //Message-TextField...
  24.     var msg_textformat = new TextFormat();
  25.     msg_textformat.font = "_sans";
  26.     msg_textformat.size = 12;
  27.     //
  28.     mc.createTextField("msg_txt", 1, 0, 0, 200, 200);
  29.     mc.msg_txt.background = true;
  30.     //mc.msg_txt.border = true;
  31.     mc.msg_txt.autoSize = true;
  32.     mc.msg_txt.html = true;
  33.     mc.msg_txt.htmlText = pMsgString;
  34.     mc.msg_txt.setTextFormat(msg_textformat);
  35.     //
  36.     //Buttons...
  37.     for(var i = 0;i<pBtnObjArray.length;++i) {
  38.         var cBtn = mc.createEmptyMovieClip("btn"+i+"_mc", i+2);
  39.         //set _y position of button 
  40.         cBtn._y = mc.msg_txt._height+5;
  41.         //TODO: center buttons in messageBox, unternanderstelling of buttons in messageBox
  42.         if(i>0) {
  43.             cBtn._x += lastCreatedButton._x+lastCreatedButton._width+5;
  44.         }
  45.         //
  46.         cBtn.createTextField("btn_txt", 1, 0, 0, 5, 5);
  47.         //
  48.         cBtn.btn_txt.autoSize = true;
  49.         cBtn.btn_txt.selectable = false;
  50.         // cBtn.btn_txt.border = true;
  51.         cBtn.btn_txt.html = true;
  52.         cBtn.btn_txt.htmlText = pBtnObjArray[i].label;
  53.         btn_textformat = mc.msg_txt.getTextFormat();
  54.         cBtn.btn_txt.setTextFormat(btn_textformat);
  55.         //
  56.         var txtWidth = cBtn.btn_txt._width;
  57.         var txtHeight = cBtn.btn_txt._height;
  58.         //using color parameter, otherwise using default color
  59.         var btnCol = (pBtnObjArray[i].color == undefined) ?  0xcccccc : pBtnObjArray[i].color;
  60.         cBtn.beginFill(btnCol);
  61.         cBtn.lineStyle(5,btnCol);
  62.         cBtn.lineTo(txtWidth, 0);
  63.         cBtn.lineTo(txtWidth, txtHeight);
  64.         cBtn.lineTo(0, txtHeight);
  65.         cBtn.lineTo(0, 0);
  66.         cBtn.endFill();
  67.         //
  68.         cBtn.onRollOver = function() {
  69.             this._alpha = 70;
  70.         };
  71.         cBtn.onRollOut = function() {
  72.             this._alpha = 100;
  73.         };
  74.         //setting button action..
  75.         //save index in btn
  76.         cBtn.actIndex = i;
  77.         var btnAction;
  78.         if(pBtnObjArray[i].action == undefined) {
  79.             btnAction = function() {
  80.                 mc.removeMessageBox();
  81.                 trace("MessageBox - default action: remove MessageBox "+mc);
  82.             }
  83.         } else if(pBtnObjArray[i].target  !== undefined) {
  84.             //trace("target is definied");
  85.             btnAction = function() {
  86.                 //save action and target temporary, then remove messageBox and call action in target..
  87.                 var     fnc = pBtnObjArray[this.actIndex].target[pBtnObjArray[this.actIndex].action]
  88.                 var trg = pBtnObjArray[this.actIndex].target;
  89.                 mc.removeMessageBox();
  90.                 fnc.apply(trg);
  91.             }
  92.         } else if (typeof pBtnObjArray[i].action == "function"){
  93.             btnAction = function() {
  94.                 var fnc = pBtnObjArray[this.actIndex].action;
  95.                 mc.removeMessageBox();
  96.                 fnc();
  97.             };
  98.         } else {
  99.             trace("WARNING - MessageBox - could not define action for button: "+cBtn);
  100.         }
  101.         cBtn.onRelease = btnAction;
  102.         //only for setting position of buttons
  103.         var lastCreatedButton = cBtn;
  104.     }
  105.     //
  106.     //Draw a line around all of it..
  107.     var mcHeight = mc._height+5;
  108.     var mcWidth = mc._width+5;
  109.     mc.moveTo(-10,-10);
  110.     mc.lineStyle(5,0xCFCFCF);
  111.     mc.beginFill(0xfcfcfc);
  112.     mc.lineTo(mcWidth, -10);
  113.     mc.lineTo(mcWidth, mcHeight);
  114.     mc.lineTo(-10, mcHeight);
  115.     mc.lineTo(-10, -10);
  116.     mc.endFill();
  117.     //
  118.     //Align / set position of  MessageBox
  119.     if(pX !== undefined) {
  120.         mc._x = pX;
  121.     } else {
  122.         //align box in center of Stage
  123.         mc._x = Stage.width/2 - mc._width/2;
  124.     }
  125.     if(pY !== undefined) {
  126.         mc._y = pY;
  127.     }else {
  128.         //align box in center of Stage
  129.         mc._y= Stage.height/3 - mc._height/2;
  130.     }
  131.     //return reference to messageBox
  132.     return mc;
  133. };
  134. //  //
  135.  
  136. /*//usage
  137. #include "createMessageBox.as"
  138. //----
  139. obj = {nm:"hello this is 'obj.nm'"};
  140. obj.jepp = function() {
  141.     trace("jepp");
  142.     trace(this.nm);
  143.     createMessageBox("Wollen Sie wirklich wirklich?", 1, [{label:"Ja, sicher!", color:0xA9DC98, action:function () {
  144.         createMessageBox("ENDE", 1, [{label:"ok", action:function () { trace("ende");}}]);
  145.     }}, {label:"Nein, ich hab's mir nochmal überlegt.", color:0xFC8274}]);
  146. };
  147. createMessageBox("Wollen Sie wirklich?", 1, [{label:"Ja!", action:"jepp", target:obj, color:0xA9DC98}, {label:"Nein!", color:0xFC8274}]);
  148. */

mfg,
a

ps.: sorry for the amateur english
..und die komische formatierung

Geändert von andilab (07-05-2004 um 23:14 Uhr)
andilab 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:10 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele