dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: "Right to left" input text

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    15

    "Right to left" input text

    hi friends..

    in an input textfielt i try to reverse writing directions for numbers.

    i use only numbers.. i need just a simple code to reverse writing directions as right to left.

    I found a code but it is not working.. it is like this;

    String.prototype.reverseSpecial = function() {
    // ------ Parse text into numeric & string chunks
    var chunks = [];
    var mode = "";
    var lenMax = this.length;
    for (var len = 0; len<lenMax; len++) {
    if (this.charAt(len)+1 && this.charAt(len) != " ") {
    // This character is numeric
    if (mode != "num") {
    mode = "num";
    chunks[chunks.length] = this.charAt(len);
    // Start new numeric chunk
    } else {
    chunks[chunks.length-1] += this.charAt(len);
    // Add to current numeric chunk
    }
    } else {
    if (mode != "str") {
    mode = "str";
    chunks[chunks.length] = this.charAt(len);// Start new text chunk
    } else {
    chunks[chunks.length-1] += this.charAt(len);// Add to existing text chunk
    }
    }
    }
    // ------ Create output : reverse all non-numeric chunks
    var outString;
    for (var arr in chunks) {
    if (String(Number(chunks[arr])) != "NaN") {
    } else {
    chunks[arr] = chunks[arr].reverseString();
    }
    outString += chunks[arr];
    }
    return outString;
    };
    String.prototype.reverseString = function() {
    var out;
    var len = this.length;
    while (len--) {
    out += this.charAt(len);
    }
    return out;
    };

    trace("This is a test sentence 1234 this is a test sentence 3.141592".reverseSpecial());
    // 3.141592 ecnetnes tset a si siht 1234 ecnetnes tset a si sihT


    any idea ????

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    if you use a Flash 8 TextInput component you can use its
    changed event to swap the order on text input.
    PHP Code:
    /*
    TextInput component on Stage - instance name: inp
    */

    var inp:mx.controls.TextInput;
    inp.restrict "0-9";
    temp = new Array();

    var 
    ti:Object = new Object();
    ti.change = function(obj:Object) {
    arr = new Array();
    len inp.text.length;
    temp.push(inp.text.charAt(len-1));
    for(var 
    n=temp.length-1n>=0n--) arr += temp[n];
    inp.text arr;

    trace("temp = "+temp);
    trace("text = "+inp.text);
    };

    inp.addEventListener("change"ti); 
    hth

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