Solved

Manipulate input text size to two different sizes in one field

Posted on 2011-03-16
9
485 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

746 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

13 Experts available now in Live!

Get 1:1 Help Now