-
AS2 entered text conversion
Hi, Please help me with this task:
There are two text boxes in the first input field for example a sentence or a set of words separated by commas
(Courage, Paris, floor, circulation, apple, and all in that order) and in the second text field text should be converted by pressing a button for example, and in front of each word must be placed space, quotes, space ("), and after each word, again quotes commas but with no spaces. How to do it?
"Courage", "Paris", ...
(As I understand the input field converting into an array, and then through the loop is every word processed and then write in the output text.)
code must be in AS2
-
.
Hi,
Lets see what code you have right now.
-
.
Hi,
Had some time, so without seeing your code or file.
So with a new AS2 document
one input textfield called "box1"
one dynamic textfield called "box2"
one button called "but"
all on stage, posssibly need to embed fonts.
PHP Code:
// *** Declare vars...; var tempArray:Array = new Array(); var wordArray:Array = new Array(); var i:Number; var j:Number;
// *** Button function; but.onPress = function():Void { // *** Clear ouptput text if re run; box2.text = ""; // Disable button while functions run; this.enabled = false; // *** Call function with input text; makeArray(box1.text); };
// *** Create arrays; function makeArray(arg:String):Void { // *** Create array of words from text input, including spaces; tempArray = arg.split(",");
// *** Create array from temp array with spaces removed; for (i = 0; i < tempArray.length; i++) { wordArray.push(stripSpaces(tempArray[i])); }
// *** Sort array if wanted; // *** Case sensitive; //wordArray.sort(); // *** Case insensitive; //wordArray.sort(Array.CASEINSENSITIVE);
trace(wordArray);
// *** Fill other text box with formatted text; for (i = 0; i < wordArray.length; i++) { //trace(stripSpaces(wordArray[i])); if (i >= (wordArray.length - 1)) { box2.text += "\" " + wordArray[i] + " \""; } else { box2.text += "\" " + wordArray[i] + " \", "; } } // *** Enable button again after functions; but.enabled = true; }
// *** Remove spaces function; function stripSpaces(stripString:String):String { // *** Replace spaces with nothing; var removedSpaces:String = ""; for (j = 0; j < stripString.length; j++) { if (stripString.charAt(j) != " ") { removedSpaces += stripString.charAt(j); } } // *** Output text with spaces removed; return removedSpaces; }
Last edited by fruitbeard; 03-28-2015 at 01:45 PM.
-
.
Hi,
Slight alteration if you re run it more than once;
PHP Code:
// *** Button function; but.onPress = function():Void { // *** Clear ouptput text if re run; box2.text = "";
// *** Clear arrays if re run: tempArray = []; wordArray = [];
// Disable button while functions run; this.enabled = false; // *** Call function with input text; makeArray(box1.text); };
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
|