PDA

View Full Version : [FMX] format user input text with punctuation



SueS
January 12th, 2005, 10:23 PM
Hi,

The tutorials on your site are terrific--thanks! I'm fairly new to Flash (over the last few months I have followed Actionscripting in books and online tutorials and can do basics by essentially following the recipes, but am having considerably more problems putting it all together for my own program).

I am trying to create a program for my students that will take their text input in fields like author, title, publisher, date, place of publication, etc. and output bibliography citations in the proper format (complete with punctuation). What is the best way to handle the text formatting to add punctuation and make the citation entries? Your text tutorial on color and other properties is very good, as well as the input text that returns the words, but how do I go one more step to add my punctuation to the user's input?

Thanks,
Sue

JKosoy
January 13th, 2005, 10:43 AM
First a disclaimer; I never really read the Kirupa tutorials so I don't really have a reference for how they taught you to do this. Anyhoo...

You could create a variable that combines all of your strings and then output the HTML text. Put a dynamic textfield on the screen and give it an instance name of final_output. Make sure HTML is enabled (in your property inspector).

Then code something like this:

var $string = "<b>" + _level0.title.text + "</b> : " + _level0.author.text;

_level0.final_output.htmlText = $string;

I can put together some kind of example for you fast if you need.

Hm. Funny that I find myself helping a school teacher, I was profoundly bad at properly citing things back in school. :)

SueS
January 13th, 2005, 06:41 PM
Thank you--I'll try this. If I have trouble making it work, I'll come back and ask for an example! I'm hoping my students will actually use this if I create it for them! You aren't alone in your experience citing sources (I think it's the tedium of it)! Maybe a spiffy new Flash app will take the tedium out of it!

Thanks again. I'll let you know how it goes with your suggestion!

JKosoy
January 14th, 2005, 12:00 AM
Please let me know how it turns out. Upload it here as well if you get it working. :)

SueS
January 17th, 2005, 01:42 PM
Nothing I try seems to make the &quot;title textfield&quot; bold when it becomes part of the concatenated string in the dynamic textfield &quot;citation_txt&quot;

I finally got the right spacing and punctuation (thanks JKOsey), but how do I bold or italicize just one item of the string? I can get it to show up for the title input textfield but then the formatting doesn't carry over to the dynamic output textfield. If I try to add html tags to the string, it no longer functions.

I'm sure it's something simple and obvious, but . . .

Thanks for any help!


Code follows:

//This creates a function that will generate the citation.
function generate () {
citation_txt.text = lastName_txt.text + &quot;,&quot; + &quot; &quot; + firstName_txt.text + &quot;.&quot; + &quot; &quot; + title_txt.text + &quot;.&quot;;
}
//This script makes the format button do its thing! Put it at end of actions scripts.//


format_btn.onRelease = function() {
generate();
}




Please let me know how it turns out. Upload it here as well if you get it working. :)

JKosoy
January 17th, 2005, 03:09 PM
There are four things you need to do:

1) Make sure in your property inspector that you have HTML text enabled. Look for the "<>" icon on your property inspector when you select the textfield.


2) Make sure to embed your fonts via the "Character..." button in that same inspector.

3) Create two dynamic textfields offstage and embed them with bold and italic fonts. This is the easiest way (that I know of) to make sure that bold and italic fonts get embedded. Sorry I didn't mention that earlier.

4) Change citation_txt.text to citation_txt.htmlText in your code.

http://www.firstfloor.net/inspector.gif

SueS
January 26th, 2005, 09:01 PM
Hi JKosey,

Thanks for your help. I've made some progress because of your suggestions. I was hoping to pull it all together and post it for you, but now, I'm stalled again and beginning to think I chose something too complex to start with.

Since the individual citation is now working, I thought I could create mc's for each different kind of citation (single author book, multi author book, journal article etc). With a click of a button, a new mc would replace the previous to provide new input fields and the output of these would be added to the same dynamic text box I started with. I can't figure out, though, what code would let me keep adding to the entries in the output box. Can you offer a suggestion of what type of code I should be using? I've gone back through Actionscript: Training from the Source, lynda.com tutorials, and searched this forum with the result that the only thing I know is that there's a lot I don't know!!

Also, can you offer any suggestions for how best to take the leap from being able to follow other people's code to being able to figure out how to structure your own?

Thanks,
Sue


There are four things you need to do:

1) Make sure in your property inspector that you have HTML text enabled. Look for the "<>" icon on your property inspector when you select the textfield.


2) Make sure to embed your fonts via the "Character..." button in that same inspector.

3) Create two dynamic textfields offstage and embed them with bold and italic fonts. This is the easiest way (that I know of) to make sure that bold and italic fonts get embedded. Sorry I didn't mention that earlier.

4) Change citation_txt.text to citation_txt.htmlText in your code.

http://www.firstfloor.net/inspector.gif