Groups | Blog | Home
all groups > flash actionscript > february 2005 >

flash actionscript : Random Characters + Typewrite


Erzek
2/1/2005 10:01:31 PM
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

Laiverd.COM
2/1/2005 11:42:37 PM
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

Laiverd.COM
2/2/2005 10:19:38 AM
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
2/2/2005 10:55:15 AM
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
---------------------------------------------------------------------------------------

AddThis Social Bookmark Button