# Dynamic textfield

**URL:** https://forum.kirupa.com/t/dynamic-textfield/6333
**Category:** flash
**Created:** [October 4, 2002, 12:19pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333 "2002-10-04T12:19:18Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Stanley](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Stanley](https://forum.kirupa.com/u/Stanley)
#### Post date: [October 4, 2002, 12:19pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/1 "2002-10-04T12:19:18Z")

</div>

Hello !

I have a textfield with a lenght of 248 chars.  
I want to load an external file into this field and when the number of chars exceeds 248 I want it to display "… (click button x for more) " at the end of the text.

Any of you know how this works?

thanx

Stan

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 4, 2002, 3:56pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/2 "2002-10-04T15:56:10Z")

</div>

[size=1]example?

/unflux[/size]  
:cyclops:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 4, 2002, 4:56pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/3 "2002-10-04T16:56:10Z")

</div>

if you’re loading text into a dynamic textfield from an external file then you can’t put any symbols into that field as well. the button telling them to click would have to exist outside the field although you could put it on top of the field in another layer.

you could write a script that checks the char length of the text string being loaded into the text field and tell it to gotoAndStop(2) when it hits 248 … on frame 2 you would have the textfield and all your other stuff as well as the button to click for more.

what is this for? i can’t think of any use for it so i’m kinda curious 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 4, 2002, 5:01pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/4 "2002-10-04T17:01:04Z")

</div>

I am kind of curious too. I am curious as to why you would rather have a more button than use the scrollbar component in Flash (or create your own scrollbar, which is a pain).

And what do you want the more button to do? Load the rest of the text? Or play different frame?

To play a different frame it would be something like…

```auto
	if (_root.myText.length>=248) {
		gotoAndStop(2);
	}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 4, 2002, 5:31pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/5 "2002-10-04T17:31:17Z")

</div>

Well guys,

The reason I needed this was that I am working on a site ([http://www.tempus-arti.org/intro.html](http://www.tempus-arti.org/intro.html)) in which I use fairly small textfields. The text is loaded from a mysql database. I wanted people to see the first sentences from the different texts and (a bit CNN and other large content - style sites ) if they wanted more, they could click a button and the whole text would show in the next loaded movie.

Dammit, It’s kinda hard to explain.

But anyway, I skipped the whole Idea, cause it’s kinda crappy looking.

But now I have another problem:  
The text in my flash-file looks really f\*cked up.  
Everytime I need a sentence to start on the next line, I get a wide gap. How do I import html break - tags?  
I am using flashMX. And the database spits out an URL encoded string. so something like " &var1=blablab&var2=blablab&var3=blabal…"

hope you can help.  
This thing needs to be up and running by monday…aargh

Stan

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 4, 2002, 5:37pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/6 "2002-10-04T17:37:16Z")

</div>

Sounds like you are in a jam.

You will first have to HTML enable your dynamic text box to accept html code. For example…

```auto
text = "This is my dynamic text";
_root.myTextBox.html = true;
_root.myTextBox.htmlText = text;

```

Ok, so the variable text contains the text you want to show in the textbox. I didn’t add html code in it yet, because if I did, the board would convert it. You can test it out if you would like.

That should be easily adaptable to your current text area.

Now to get rid of that annoying gap. The gap happens if you hit enter in your text. To prevent the gap use a [BR] (replace [] with \<\>) tag between lines to prevent that other than hitting the enter button on your keyboard. So your sentence structure would look like…

This is my first line of text[BR]and this is my second line of text[BR]and this is my third line of text,etc.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 4, 2002, 6:00pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/7 "2002-10-04T18:00:12Z")

</div>

Hmmm…  
this doesn’t really do the trick.

All I get now is a number instead of my text (1911). ??

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 4, 2002, 6:10pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/8 "2002-10-04T18:10:34Z")

</div>

Hmmm? That must be something your database is spitting out because the code I gave you has nothing to do with numbers.

the variable “text” that I gave you in my example should be changed to the variable that loads your external text of course.

```auto
loadText = new loadVars();
loadText.load("myText.txt");
loadText.onLoad = function() {
	    _root.myText.html = true;
                    _root.myText.htmlText = this.myTextVariable; 
};

```

Then in your external .txt file it will be set up as myTextVariable=this is the text you write

Maybe that will help???

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 5, 2002, 10:05am UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/9 "2002-10-05T10:05:16Z")

</div>

Hey,

back again, with the same result.  
it doesn’t work:

I’m gonna take this from a new angle.

When I enter my data in my form:

I’m adding some PHP:

$var = nl2br($var);  
(should replace new lines with breaks…)

I’ll get back with the result…

greets  
Stanley

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 5, 2002, 4:55pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/10 "2002-10-05T16:55:49Z")

</div>

Just for the record, the answer to your previous problem would be something like this:

```auto
myString=new String("abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef");
if (myString.length>20 ){
	var a=myString.substr(0,20 );
	a+="... click for more";
	trace (a);
}

```

You’d have to replace myString with what you get from your database.

pom 😏

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 5, 2002, 6:12pm UTC](https://forum.kirupa.com/t/dynamic-textfield/6333/11 "2002-10-05T18:12:18Z")

</div>

Great code ! thanks. Clean, simple effective. nice

But I’m still stuck with my second problem.

–\> When I enter data in a database via a form, and then retrieve it via php to flash, all the [br]breaks I entered (just by pressing enter or shift-enter ) in my text end up as a blank line in my textfield.

The output from my php mysql\_query  
looks like this (if I manually ad [br]-tags):

var1=balbalbalb[br]bakakbakba[br]balbalba &var2=lkdslkjfdsl  
&var3=blablaba

I load these values into the \_root of my movie, so I easely know where to find them.

loadVariables(“path/getvalues.php”, \_root);

then I use the code you gave me to display the vars in the dynamic textfields:

\_root.textbox.html = true;  
\_root.textbox.htmlText = \_root.var1;

and this, Flash won’t take  
It would take it if the values were between “quotation marks”  
How can I get the values of my vars between quotation marks?  
“”"+var1+""" doesn’t work.
