Solved

Manipulate input text size to two different sizes in one field

Posted on 2011-03-16
9
486 Views
Last Modified: 2013-11-11
Hi there,
I have an input text field with an CHANGE event listener. As the user enters text I'd like to modify the display of the text so that if they enter 25000, 25 is larger than 000.

So far I've only been able to use a substr on the field and trace the output.

Is this possible?
0
Comment
Question by:pixystk
  • 4
  • 3
  • 2
9 Comments
 
LVL 10

Expert Comment

by:Carnou
ID: 35151218
If you set the .htmlText member of the text field instead of the .text member, you can put an HTML string in there.  You should then be able to use regular html formatting.

A simple example:


textfield.htmlText = "<font size='10'>25</font><font size='4'>000</font>";

Of course, if you're making substrings, just add those in:

textfield.htmlText = "<font size='10'>" + sub_string_1 + "</font><font size='4'>" + sub_string_2 + "</font>";

You can use this to set color, font size, or just about anything else.  Hope this helps!
0
 

Expert Comment

by:BlakeRogers
ID: 35152422
Basically you just need to use the autoSize on a text field in actionscript if I understand your problem correctly.
Var myText:TextField  = new TextField();

myText.autoSize = TextFieldAutoSize.LEFT;

Open in new window

0
 

Author Comment

by:pixystk
ID: 35157732
@Carnou - I like the idea of using htmlText, but now I'm running into an issue with my substr... it keeps throwing errors (coercion and undefined method substr). Can you take a look and see what I'm doing wrong?

And... @BlakeRogers  - what does AutoSize do? I don't understand how that would work being that it doesn't necessarily know which characters to apply the size to.

 inputTextTest.zip
0
 

Expert Comment

by:BlakeRogers
ID: 35157827
Is there a definite number of characters that will have a different size every time?

For instance the string "Happy" has 5 characters and even if the string grows we want the first 2 characters "HA" to be in a bigger font.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:pixystk
ID: 35157980
Yes...
if there are 5 chars then the first two will be larger than the last three.
25 big 000 small. If there are four chars, then for 2500 the 2 is big and the 500 is small.
if there are only three chars, then all three are small.
0
 

Expert Comment

by:BlakeRogers
ID: 35158446
This is the best way that I know to do this... You should be able to cut and past this into an actions layer of an fla. After this you would just need to concat the strings. Let me know if you need help with that.

var str:String = "Happy Monday";

//trace(str.slice(0,5));
/*do the above to make sure that you get the amount you want. Don't forget double index*/

var strModify:String = str.slice(0,5);
var strLeftOvers:String = str.slice(6, str.length);

//trace(strModify);
//trace(strLeftOvers);

Open in new window


~Blake
http://www.onyxtekwebdesign.com
0
 

Expert Comment

by:BlakeRogers
ID: 35158462
The above would allow you to change the size independently, but mash them together for like a texfield output.
0
 
LVL 10

Accepted Solution

by:
Carnou earned 500 total points
ID: 35160180
Sorry it took me so long to respond... personal issues kept me away from my computer till now.

Your fla has close to what you need.  The problem is that you set AltValA and B to be Numbers instead of Strings.
I'm including a version that works.  Once you click in the text field and modify the field, you'll see the results.

Just be careful of which variable is of what type, and the text manipulation becomes easy.

Let me know if you have any questions.
inputTextTest.fla
0
 

Author Closing Comment

by:pixystk
ID: 35160374
Thanks!
I was going in circles swapping out variables trying to find what was wrong. Thanks for taking a look at that and thanks for the htmlText solution, it's exactly what I wanted!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now