dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Pointer about textbox and word wrap

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    78

    Pointer about textbox and word wrap

    Hi,
    I've got an array showing in a dynamic texbox with word wrap and multi - line.
    a = ['one','two','three','four','five','six','seven','e ight','nine','ten', '-'];
    How can I get the textbox to recognise the comma and move the next whole word to the next line if the first line is full. At the moment it just splits the word ie
    thr
    ee,

    I have to make each word with a space in it eg ' one' to work at the moment.
    thank you
    ja
    Last edited by jarnold; 09-11-2009 at 02:07 AM.

  2. #2
    Senior Member
    Join Date
    Jan 2004
    Posts
    141
    I'm not sure what you're trying to achieve, but you could try adding the space in your array of values?
    Code:
    a = [' one',' two',' three',' four',' five',' six',' seven',' eight',' nine',' ten', ' -'];
    The reason it's wrapping as you describe is because there are no spaces in the string. You could also populate the text box using actionscript on a frame (in this eg 'test' is the instance name on the textbox):

    Code:
    for (var i=0; i<a.length; i++)
    {	
    	test.text = test.text + a[i] + " ";
    }

  3. #3
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    Just in case you require that the text contains no spaces, I've written a function which will write an array into a textfield and wrap it on commas:
    Code:
    var a:Array = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "-"];
    function wrapArray(a:Array, t:TextField):Void {
    	var m:Number = 0;
    	while(t.textWidth < t._width-5) t.text += "o", m++;
    	t.text = "";
    	var s:Array;
    	var l:Number = a.length;
    	var p:Object;
    	var d:Number = 0;
    	for(var z = 0; z<l; z++) {
    		t.text += a[z]+(z==l-1?"":",");
    		if(t.text.length - d > m) {
    			s = t.text.split(",");
    			p = s.pop();
    			d = s.join(",").length;
    			t.text = s.join(",")+",\n"+p;
    		}
    			
    	}
    	
    }
    wrapArray(a, textFieldInstance);
    It's very crude, and by no means perfect, but it does the job. Tweak it as much as you need.
    New sig soon

  4. #4
    Member
    Join Date
    Aug 2008
    Posts
    78
    Thanks Captain Planet and dudeqwerty for replying - I have used the " one" in the arrray - didn't express it well so thanks for verifying the method and I'll try the AS in the textbox. The function looks good if I import a text string instead of hard wiring an array in the code. Very helpful folks here. Thank you again.
    John

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