-
Senior Member
[F8] replacing newline with space
i'm trying to replace all the carriage returns with spaces, from an input text box like this:
Code:
myText.split(newline).join(" ");
that doesn't work, i've also tried to use "\n" and "\r" instead of newline, but neither work. it just leaves it the way it is
p.s. using flash 8 pro
Last edited by tu_dor; 09-30-2006 at 02:55 PM.
-
Flashmatics
suppose your textfield has instance name myText then use, you may have to replace the "\r" with "\n" or even "\r\n" all depends on how your text has been broken up on new lines..
Code:
myText.text = myText.text.split("\r").join("");
-
Senior Member
no, still doesn't work... it doesn't recognize the newline character. i used newline, "\n", "\r", and now, "\r\n".
-
Flashmatics
upload ur fla ..works fine on my machine
-
Senior Member
it won't let me upload it, so i'll describe it.
- an input text field with variable name "original_text" and instance name "text_input"
- a dynamic text field with variable name "final_text"
- another dynamic text field - var name "word_count_status"
- a Randomize button, instance name "r_but"
this is the script on the first frame:
Code:
fscommand("showmenu", "true");
Array.prototype.randomize = function() {
var len = this.length;
var temp = new Array();
for (var i = 0; i<len; i++) {
var ran = Math.round(Math.random()*(this.length-1));
temp[i] = this[ran];
this.splice(ran, 1);
}
for (var j = 0; j<len; j++) {
this[j] = temp[j];
}
};
text_input.html = false;
original_text = "";
r_but.useHandCursor = false;
onEnterFrame = function () {
words_array = original_text.split(" ");
word_count = words_array.length;
if (words_array[words_array.length-1] == "") {
word_count--;
}
word_count_status = word_count+" words";
};
and this is the code on the randmomize button:
Code:
on (release) {
original_text.text = original_text.text.split("\n").join(" ");
words_array = original_text.split(" ");
words_array.randomize();
final_text = words_array.join(" ");
}
the only part that doesn't work is the code on the randomize button
-
FK'n_dog
I have -
input textfield - multiline - instance name - input_text ( no var: name)
input_text has this text -
this is a test
and another test
and another test again
dynamic textfield - multiline - var: name - final_text
dynamic textfield - single line - var: name - word_count_status
button - instance name - r_but
all on frame#1 with this code -
Code:
words_array = text_input.text.split(" ");
word_count = words_array.length;
if (words_array[words_array.length-1] == "") {
word_count--;
}
word_count_status = word_count+" words";
r_but.onRelease = function() {
text_input.text = text_input.text.split("\r").join(" ");
words_array = text_input.text.split(" ");
words_array.sort(function(){return Math.floor(Math.random()*3)-1});
final_text = words_array.join(" ");
}
when r_but is released, the (typical) output in final_text is -
this and again another test another and test test a is
or
another and is test this a and another test test again
or
another is this and and test test a another test again
is this close to what you are trying to achieve ??
-
Senior Member
many thanks, it's perfect.
still, i can't understand this part:
Code:
words_array.sort(function () {
return Math.floor(Math.random()*3)-1;
});
i looked in the actionscript reference for "array.sort method" but i couldn't understand the explanation
-
FK'n_dog
words_array.sort(function(){return Math.floor(Math.random()*3)-1});
this does pretty much the same as - Array.prototype.randomize
place a trace before and after to see the results -
trace(words_array);
words_array.sort(function(){return Math.floor(Math.random()*3)-1});
trace(words_array);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|