A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS2 entered text conversion

  1. #1
    Registered User
    Join Date
    Mar 2015
    Posts
    1

    Smile 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

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    Lets see what code you have right now.

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    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 (0tempArray.lengthi++)
        {
            
    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 (0wordArray.lengthi++)
        {
            
    //trace(stripSpaces(wordArray[i]));
            
    if (>= (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 (
    0stripString.lengthj++)
        {
            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.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center