-
[RESOLVED] How change color of only one word in text field
Hi !
Inside an animation _ CS4 - AS2 _ (a part of a self creative digital painting)
with clip BUTTONS to CLIC for writing in a text field
(and not by typing with the computer keyboard)
I wish, after clic on a "color button", to put a new text color to ONLY ONE (or few) of the next words during the writting...
The last others words having to be saved in their own first color, and idem when write after with the first back color.
See the linked file (cs4) for what works and what I'd wish exactly.
https://www.dropbox.com/s/s10l1vvl23...Ftest.fla?dl=0
_Notes_
1) Change the color of the full text field (built with a script) and back is ok.
2) I red a lot in the "flash reference guides", and many forums, but without real success.
At least I think one of the ways to follow is, may be, to put something like a "listener" for getting and sending in the script change color the "begintIndex" and "endIndex" of the next word to give a new color inside the text field... May be other more simple way ?
But, these "listener" and get "beginIndex..." I'm quite unable to work with !
(I'm just a painter very interested with encoding...) !
Thanks for your reading
-
.
Hi,
You might find it easier to use a string for the text filed,
I have out all the code on one fcrame for ease for me.
PHP Code:
var font1:String = "0000FF"; var font2:String = "00FF00"; var textString:String = "<font color='#" + font1 + "'>";
var my_fmt:TextFormat = new TextFormat();
my_fmt.bold = false; my_fmt.font = "Palatino Linotype"; my_fmt.size = 22;
// Create frame text field to display player's stat's comment. this.createTextField("enter_Field",5000,20,10,150,200);// (20x 10y, L, h) enter_Field.setNewTextFormat(my_fmt); enter_Field.selectable = true; enter_Field.type = "dynamic"; enter_Field.html = true; enter_Field.multiline = true; enter_Field.htmlText = textString;
var keyboard:Array = new Array("a", "e", "i", "o", "u", "b", "c"); for (v = 0; v < 8; v++) { this[keyboard[v]].keyLabel = keyboard[v]; this[keyboard[v]].onPress = function() { this.gotoAndPlay("down"); doColour(this.keyLabel); }; }
doEnter.onPress = function() { textString += "<br />"; enter_Field.htmlText = textString; this.gotoAndPlay(2); };
doClear.onPress = function() { this.gotoAndPlay(2); colorTF._visible = true; colorBack._visible = false; textString = "<font color='#" + font1 + "'>"; enter_Field.htmlText = textString; };
colorTF.onPress = function() { this.gotoAndPlay(2); coul(); colorBack._visible = true; };
colorBack.onPress = function() { this.gotoAndPlay(2); coulBack(); colorTF._visible = true; };
colorBack._visible = false;
function coul():Void { colorTF._visible = false; textString += "</font><font color='#" + font2 + "'>"; }
function doColour(input:String):Void { textString += input; trace(textString); enter_Field.htmlText = textString; }
function coulBack():Void { colorBack._visible = false; textString += "</font><font color='#" + font1 + "'>"; }
I have renamed the enter button and the clear button to doEnter and doClear as you might end up clashing with bult in functions using those names
Last edited by fruitbeard; 05-09-2016 at 11:40 AM.
-
your change color is OK
Weeuouhhh !
you really are a magician, Fruitbeard !
Thanks'a lot for your string's script that works very well.
Exactly what I looked for...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|