Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-27-2005, 10:31 AM   #1
geecu
Registered User
 
Join Date: Feb 2005
Posts: 2
Default setTextFormat input button (it's not about setNewTextFormat)

Hi,

I'm pretty new to AS2.0, don't know if this problem is AS2.0 or older. I've jumped from Flash4 AS straight to AS2.0.

I've encountered a very strange (to me) problem regarding the input fields. Basically, I want to add a certain character to an input. The problem occurs when using two different textformat for chars in the input. When you input a char before a different styled char (then the default), and then add (through AS) another char, the whole input changes the default to the other style.

I've simplified the problem as much as possible, still, the problem is there. Just paste the below code into a new movie, test the movie (does the same in browser), place your caret before the bolded character (5), and input something. In my version, the whole input gets bolded... hope it's the same on yours.

ActionScript Code:
var my_fmt:TextFormat = new TextFormat(); my_fmt.bold = true; _root.createTextField('txt',_root.getNextHighestDepth(),0,0,150,100); txt.type = 'input'; txt.text = '012345'; txt.setTextFormat(5, my_fmt); txt.onChanged = function(t){     txt.text += 'x'; }

- It doesn't matter where the new char is added (I put it at the end of the string, but you can put it at the beginning or in the middle.
- It doesn't matter whether you specify a setNewTextFormat or not
- It doesn't matter if you use embedded fonts or not

Note: it doesn't enter an infinite loop as (from the manual) the onChanged is fired only when the input changes as a consequense of a user action.l

I've just discovered, while trying to work with htmlText, that if you add some HTML code in the onChanged function, you have to move the caret to be able to insert again. Pressing any key doesn't make any change... strange

Now: please spare me! Even if you don't know the solution, but it seems odd to you too, please tell me - so I know it's not my fault. Or if it seems right to you (the way it acts), please tell me, even if you don't have any logical explanation... I'm on my 8th hour of searching the internet and testing different stuff...

Regards,
GK
geecu is offline   Reply With Quote
Old 02-27-2005, 11:27 AM   #2
UncleML
Registered User
 
UncleML's Avatar
 
Join Date: Feb 2005
Posts: 234
Default

Your new discovery intrigued me to test it out, to search for any reported bugs, and to work around with the code. And herewith, I read that someone has already reported this to Macromedia and yet to receive any reply from them.
Quote:
CheloXL said on Feb 17, 2005 at 6:27 AM :
That´s not true.
To the example code, add the following lines to the end:
my_fmt.color = 0xFF0000;
my_txt.setNewTextFormat(my_fmt);
Now, test it. If you insert some text AT THE END of the string, it works. But if you insert some text in the middle of the written text, it doesn´t work.
Just playing around with the code, I've finally worked out a solution that does the trick. Just that you need two text formats, one for the normal one, and the other for the bold one.
Code:
var my_fmt:TextFormat = new TextFormat();
my_fmt.bold = true;
var my_fmt2:TextFormat = new TextFormat();
my_fmt2.bold = false;

_root.createTextField("txt",_root.getNextHighestDepth(),0,0,150,100);
txt.type = "input";
txt.text = "012345";
var ifmt:Number=txt.length;
txt.setTextFormat(0,ifmt,my_fmt);   //txt.setNewTextFormat(my_fmt) also will do fine for the initial start
txt.onChanged = function(t){
             txt.text += "x";
	txt.setTextFormat(0,ifmt,my_fmt);
	txt.setTextFormat(ifmt,txt.length,my_fmt2);
}
UncleML is offline   Reply With Quote
Old 02-27-2005, 08:55 PM   #3
geecu
Registered User
 
Join Date: Feb 2005
Posts: 2
Default 10x

Hi,

10x alot for looking into it. I know it intrigued you, and this is (probably) the main reason you looked into you, but 10x for replying at least

Damn, and I thought I'd get the chance to report a bug to MM

Well, your solution wasn't exactly what I wanted, but the problem could probably solved like that: keeping the positions of "special" chars (those that receive another formatting than the default one), and onChanged change the whole format to the default one, then search for special chars. That would work (probably) but it would be a bit messy.

What I needed was to add a special char (different formatting) after (or before) the caret, when a special key is pressed (in my case I chose SHIFT+ENTER, but that doesn't matter). I've finally used textFIeld.text.replaceSel('x') and it works... like a charm... well, with a few tricks. Don't ask me why I haven't used that in the first place, and chose to spend about 8hrs trying to figure it out the other way round...


10x again for your reply.

Regards,
GK
geecu is offline   Reply With Quote
Old 02-28-2005, 01:44 AM   #4
UncleML
Registered User
 
UncleML's Avatar
 
Join Date: Feb 2005
Posts: 234
Thumbs up

Great! You've worked out a solution. I thought that was initially your problem I tested out too and used my solution to tackle the problem of lost format of the first 6 digits during input. It's a challenge to have to try out various methods, I'm learning too. Would like to hear more of such interesting findings from you.
UncleML is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:41 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.