Can someone help me on this? I would like to display random characters from a length's text and then displayed the real text. Example: 2 or 3 seconds showing random chars and later the typewrite funcion displayed the real text. (I know how to make the typewrite effect script) Help will be very appreciated! Thanks
Just created something similar (but without the typewriter effect); you'll get the id Create a dynamic textfield called "test_txt" Then copy/paste the below code to the same frame that holds the textfield: TextField.prototype.throwString = function (updatefrequency, numrepeats, str) { u = updatefrequency; n = numrepeats; // turn string into array s = str.split (""); // create object with properties if not existing if (!this.Obj) { this.Obj = new Object (); // array for randomising string this.Obj.chars = new Array ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "!", "@", "#", "$", "%", "&", "+", "?"); // counter to compare to n this.Obj.c = 0; } // function that throws random chars this.doString = function () { // update counter this.Obj.c++; // reset textfield ns = ""; // loop through s array (representing all chars in the string) for (i = 0; i < s.length; i++) { // check for space if (s[i] == " ") { ns += " "; } else { x = this.Obj.chars[Math.ceil (Math.random () * this.Obj.chars.length) - 1]; ns += x; } // trace (i + " : " + x); } // trace (ns + " : " + ns.length); this.text = ns; if (this.Obj.c == n) { this.text = str; clearInterval (this.Obj.id); } }; this.Obj.id = setInterval (this, "doString", u); }; // calling the prototype function test_txt.throwString (20, 50, "laiverd is me"); John
Oops: little mistake. This: // create object with properties if not existing if (!this.Obj) { this.Obj = new Object (); // array for randomising string this.Obj.chars = new Array ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "!", "@", "#", "$", "%", "&", "+", "?"); // counter to compare to n this.Obj.c = 0; } Should be : // create object with properties if not existing if (!this.Obj) { this.Obj = new Object (); // array for randomising string this.Obj.chars = new Array ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "!", "@", "#", "$", "%", "&", "+", "?"); } // counter to compare to n this.Obj.c = 0; John -- --------------------------------------------------------------------------------------- RESOURCES http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash --------------------------------------------------------------------------------------- TUTORIALS at www.laiverd.com Flash & PHP Emailform Using textfiles in Flash --------------------------------------------------------------------------------------- [quoted text, click to view] "Laiverd.COM" <share_your_knowledge@someserver.com> wrote in message news:ctp0kt$kt0$1@forums.macromedia.com... > Just created something similar (but without the typewriter effect); you'll get the id > > Create a dynamic textfield called "test_txt" > Then copy/paste the below code to the same frame that holds the textfield: > > TextField.prototype.throwString = function (updatefrequency, numrepeats, str) { > u = updatefrequency; > n = numrepeats; > // turn string into array > s = str.split (""); > // create object with properties if not existing > if (!this.Obj) { > this.Obj = new Object (); > // array for randomising string > this.Obj.chars = new Array ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", > "u", "v", "w", "x", "y", "z", "!", "@", "#", "$", "%", "&", "+", "?"); > // counter to compare to n > this.Obj.c = 0; > } > // function that throws random chars > this.doString = function () { > // update counter > this.Obj.c++; > // reset textfield > ns = ""; > // loop through s array (representing all chars in the string) > for (i = 0; i < s.length; i++) { > // check for space > if (s[i] == " ") { > ns += " "; > } else { > x = this.Obj.chars[Math.ceil (Math.random () * this.Obj.chars.length) - 1]; > ns += x; > } > // trace (i + " : " + x); > } > // trace (ns + " : " + ns.length); > this.text = ns; > if (this.Obj.c == n) { > this.text = str; > clearInterval (this.Obj.id); > } > }; > this.Obj.id = setInterval (this, "doString", u); > }; > // calling the prototype function > test_txt.throwString (20, 50, "laiverd is me"); > > John >
Darn discovered another bug (interval wasn't cleared when the function was called quickly after another call). So for now an improved version: TextField.prototype.throwString = function(updatefrequency, numrepeats, str) { u = updatefrequency; n = numrepeats; // turn string into array s = str.split(""); // clear any current interval clearInterval(this.Obj.id); // create object with properties if not existing if (!this.Obj) { this.Obj = new Object(); // array for randomising string this.Obj.chars = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "!", "@", "#", "$", "%", "&", "+", "?"); // counter to compare to n } this.Obj.c = 0; // function that throws random chars this.doString = function() { // update counter this.Obj.c++; // reset textfield ns = ""; // loop through s array (representing all chars in the string) for (i = 0; i < s.length; i++) { // check for space if (s[i] == " ") { ns += " "; } else { x = this.Obj.chars[Math.ceil(Math.random() * this.Obj.chars.length) - 1]; ns += x; } // trace (i + " : " + x); } // trace (ns + " : " + ns.length); this.text = ns; if (this.Obj.c == n) { this.text = str; clearInterval(this.Obj.id); } }; this.Obj.id = setInterval(this, "doString", u); }; -- --------------------------------------------------------------------------------------- RESOURCES http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash --------------------------------------------------------------------------------------- TUTORIALS at www.laiverd.com Flash & PHP Emailform Using textfiles in Flash ---------------------------------------------------------------------------------------
Don't see what you're looking for? Try a search.
|