Solved

Manipulate input text size to two different sizes in one field

Posted on 2011-03-16
9
487 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
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 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.

772 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