Solved

Manipulate input text size to two different sizes in one field

Posted on 2011-03-16
9
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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
 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

705 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