MagicLetter Flash Class: una classe per le scritte magiche

Come promesso ecco la versione aggiornata del simpatico effetto delle scritte magiche. Ho realizzato una diversa animazione per la “lettera”, per mostrare quanti effetti si possono fare. Il sorgente completo potete scaricarlo qui.

Loading Flash Player...

Classe MagicLetter

Questo è il codice della Classe che, ovviamente, può essere modificato e migliorato ulteriormente. Ad esempio è possibile inserire un parse per supprotare un simbolo di “nuova linea”, per andare a capo insomma. Possono essere introdotte le funzioni di get e set per esportare alcune proprietà all’esterno, ed altro ancora.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
**
** file     : MagicLetter.as
** Version    : 1.0
** Author   : Giovambattista Fazioli (g.fazioli@undolog.com)
** Web      : http://www.undolog.com
** Email    : g (dot) fazioli (at) undolog (dot) (com)
** Created    : 21/10/2007 13.57
** Modified   : 22/10/2007 22.02
**
** In base ad un "linkage" MovieClip crea un'animazione testuale
**
*/

class MagicLetter {
  private var __release:String = "1.0";
  //
  private var __mc:MovieClip;
  private var __text:String = "";
  private var __timeout:Number = 50;
  private var __interval;
  private var __index:Number = 0;
  private var __linkage:String = "magicletter";
  private var __x:Number = 0;
  private var __y:Number = 0;
  /********************************************************************************************
  ** Costruttore
  **
  ** Non ereditando la classe da MovieClip chiedo un puntatore ad un MovieClip (Es. _root)
  ** durante la costruzione dell'oggetto
  ********************************************************************************************/

  function MagicLetter(mc:MovieClip,n:String, d:Number){
    trace("MagicLetter::contructor");
    __mc = mc.createEmptyMovieClip(n , d);
  }
  /********************************************************************************************
  ** Show() - innesca la visualizzazione dell'animazione
  **
  ** to   - TimeOut
  ** x    - Coordinata x
  ** y    - Coordinata y
  ********************************************************************************************/

  public function Show(str:String, to:Number, x:Number, y:Number) {
    // se stringa non nulla != ""
    if (str.length > 0) {
      __timeout = to;
      __x = x;
      __y = y;
      __text = str;
      __index = 0;
      __interval = setInterval(this, "__createMagicLetter", __timeout);
    }
  }
  /********************************************************************************************
  ** __createMagicLetter() - metodo richiamato da setInterval() che aggiunge le singole animazioni
  ********************************************************************************************/

  private function __createMagicLetter() {
    var t_mc = __mc.attachMovie(__linkage, "item" + __index, (__index + 1), {_x:__x, _y:__y});
    var s_txt:TextField = t_mc.shadow_mc.letter_txt;
    var n_txt:TextField = t_mc.letter_mc.letter_txt;
    n_txt.autoSize = s_txt.autoSize = true;
    n_txt.text = s_txt.text = __text.substr(__index, 1);
    __x += n_txt.textWidth;
    __index++;
    if (__index > (__text.length - 1)) {
      clearInterval(__interval);
    }
    updateAfterEvent();
  }
}

Esempio di come usare la Classe

Questo codice può essere posizionato sul primo frame del filmato:

1
2
3
4
5
6
import MagicLetter;
// MagicLetter( movieClip, Nome, profondità );
var ml1:MagicLetter = new MagicLetter(this, "scritta1", 1);
var ml2:MagicLetter = new MagicLetter(this, "scritta2", 2);
ml1.Show("Vieni su Undolog.com e scopri altri Script", 20, 10, 50);
ml2.Show("per Adobe Flash MX!", 20, 10, 120);

Non ci sono commenti per questo Post

Lascia un commento

TAG XHTML PERMESSI: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERIMENTO CODICE:
<pre></pre> // blocco generico
					<code></code> // blocco generico
					[cc_actionscript][/cc_actionscript] // Actionscript
					[cc_actionscript3][/cc_actionscript3] // Actionscript 3
					[cc_css][/cc_css] // CSS Style Sheet
					[cc_html][/cc_html] // HTML
					[cc_js][/cc_js] // Javascript
					[cc_objc][/cc_objc] // Objective-C
					[cc_php][/cc_objc] // PHP
					[cc_sql][/cc_sql] // SQL


Stop SOPA