-
Change dynamic text color
So I have this typewriter script that looks like this:
frame 1:
Code:
firstname = "Tom";
_root.strText = "Hi "+firstname+". Allow me to introduce myself.";
_root.counter = 1;
frame 2 (labeled "loop"):
Code:
_root.text1 = _root.strText.substr(0,_root.counter);
_root.counter++
frame 3:
Code:
gotoAndPlay("loop");
I'm looking to get 'firstname' to be a different color than the rest of the text. How can I do this?
-
What version of flash are you using?
-
sorry.. using cs3 with as2.0
-
I'm using MX2004, maybe you can adapt this to want you are trying to do...
Code:
// txt1 and txt2 are instances of the same movieclip, txt2 masks txt1
// font used in dynamic text field needs to be in library and exported
stop();
var firstname = "Tom";
var firstnameHTML = "<FONT COLOR='#FF0000'>" + firstname + "</FONT>";
//
txt1.myTxt.htmlText = "Hi " + firstnameHTML + ". Allow me to introduce myself.";
//
var myStrText = txt1.myTxt.text;
var CT = 0;
txt2.onEnterFrame = function() {
txt2.myTxt.htmlText = myStrText.substr(0, CT++);
if (CT > myStrText.length) {
delete this.onEnterFrame;
}
};
//
Last edited by dawsonk; 09-03-2008 at 02:24 PM.
-
Thanks dawsonk, but I was looking to have the text be center aligned. I notice when i change this the effect doesn't work that same. I started working with another typewriter script:
Code:
var firstname = "Tom";
var phrase_string:String="Hi "+firstname+". Allow me to introduce myself";
var n:Number= phrase_string.length;
var i:Number=0;
this.onEnterFrame=function(){
if (i<n){
//display_txt is the instance of my dynamic text box
display_txt.text+=phrase_string.substr(i,1);
i+=1;
}
}
I tried to mash up what you posted
Code:
hover.fin.fish.openMov.gotoAndStop(1);
var firstname = "Tom";
var firstnameHTML = "<FONT COLOR='#FF0000'>"+firstname+"</FONT>";
var phrase_string = "Hi "+firstnameHTML+". Allow me to introduce myself.";
var n:Number = phrase_string.length;
var i:Number = 0;
this.onEnterFrame = function() {
if (i<n) {
//display_txt is the instance of my dynamic text box
display_txt.htmlText += phrase_string.substr(i, 1);
i += 1;
}
};
but my script doesn't literally spells out "Hi <FONT...."
-
i don't see much of a difference between what you posted and what i posted.. can any one explain this to me?
-
Code:
//
var firstname = "Tom";
var phrase_string = "Hello " + firstname + ". Allow me to introduce myself.";
//
var sX = phrase_string.indexOf(firstname);
var eX = sX + firstname.length;
var phraseArray = phrase_string.split("");
var n:Number = phraseArray.length;
for (j = 0; j < n; j++) {
if (j >= sX && j < eX) {
phraseArray[j] = "<font color='#FF0000'>" + phraseArray[j] + "</font>";
}
}
//
var phrase = "";
var i:Number = 0;
this.onEnterFrame = function() {
if (i < n) {
phrase += phraseArray[i];
//display_txt is the instance of my dynamic text box
this.display_txt.htmlText = "<p align='center'>" + phrase + "</p>";
i++;
} else {
delete this.onEnterFrame;
}
};
-
beautiful dawsonk! thanks a lot!
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
|