Hi, I'm very new to Flash MX and have a question for the more knowledgeable ones out there. Is it possible to use dynamic text with HTML in a movie clip and then apply alpha manipulations to the movie clip? If that doesn't make sense, here's what I'm trying to accomplish. I want to use dynamic text boxes to read a set of testimonials from an xml file. One testimonial appears, fades and then the next one appears and then fades, etc. Up to the number of items in the XML document and then have the process repeat continuously. I'd like for the testimonials to have empahsis on certain words using bold or italics or even a different sized font, hence the need for HTML. Is this possible? Thanks! Tony
Yes it is possible. You'll want to set the html property for your textfield to true, by either, clicking on Render Text As HTML in the properties panel after selecting your textfield, or using actionscript: myTF.html = true; myTF.htmlText = '<b>Emphasized!</b>'; (where myTF is the instance of your textfield) If you want to change the alpha, you are going to have to embed the font that you are using in your textfield. You can do a simple search on these Forums, for embed font, or probably even fade text. If you want me to explain in more detail, feel free to ask!
If that isn't enough, here is some sample code. First open the library. Click on the top right corner of the library menu. A menu should open. Select New Font... Then select the font you want. And hit OK. Now, right click on it, and select Linkage. Check off Export for ActionScript. Then type in myFont for the identifier. Hit OK. Then open that same menu again. Go to New Font again. This time, select the same font, but check off Bold. Hit OK. Right click, Linkage... Then check off Export for ActionScript. Type in myFont_bold. Hit OK. Do the same thing again, accept check off Italic, and for the linkage identifier use, myFont_italic. Finally, do it once more, but this time check off both bold and italic, and type in myFont_bi for the identifier. Finally paste the following code onto frame 1 of a new movie. this.createTextField("myTF", this.getNextHighestDepth(), 0, 0, Stage.width, 0); //Fonts: myTF.normalFont = 'myFont'; myTF.boldFont = 'myFont_bold'; myTF.italicFont = 'myFont_italic'; myTF.boldItalicFont = 'myFont_bi'; //Texts: myTF.myTextys = ['Normal', '<b>Bold</b>', '<i>Italic</i>', '<u>Underline</u>', '<b><i>Bold/Italic</i></b>', '<b><u>Bold/Underline</u><b>','<i><u>Italic/Underline</u></i>','<b><i><u>Bold/It alic/Underline</u></i></b>']; //Initial Settings: my_fmt = new TextFormat(); my_fmt.font = myTF.normalFont; myTF.cIndex = -1; myTF._alpha = 0; myTF.autoSize = 'center'; myTF.multiline = true; myTF.wordWrap = true; myTF.embedFonts = true; myTF.html = true; myTF.setTextFormat(my_fmt); //Start the ticker! setInterval(tickerIt,1,myTF); function tickerIt(myTF) { if (myTF._alpha<=0) { myTF.dir = 1; myTF.cIndex = (myTF.cIndex+1)%myTF.myTextys.length; myTF.htmlText = myTF.myTextys[myTF.cIndex]; formatText(myTF); } if (myTF._alpha>=100) { myTF.dir = -1; } myTF._alpha += myTF.dir; trace(myTF._alpha); } function formatText(myTF) { for (x=0; x<myTF.text.length; x++) { var c_fmt = myTF.getTextFormat(x, x+1); if (c_fmt.bold && c_fmt.italic) { c_fmt.font = myTF.boldItalicFont; } else if (c_fmt.bold) { c_fmt.font = myTF.boldFont; } else if (c_fmt.italic) { c_fmt.font = myTF.italicFont; } else { c_fmt.font = myTF.normalFont; } myTF.setTextFormat(x, c_fmt); } }
Thanks for the long and informative post. I was able to run your code, but am having problems implementing it into my movie. The thing I'm really trying to do is display a testimonial with emphasis only on certin words or phrases. Something like "This is an <i>example</i> where I am using various <b>HTML formatting</b> in the same line." I'm not sure how to do this using the example you provided. Thanks! Tony
My last code was a bit messy. First, create a new Layer, called "Ticker Code". Paste in the following script: TextField.prototype.addTicker = function() { var myTF = this; var my_fmt = new TextFormat(); my_fmt.font = myTF.fonts.normal; myTF.setTextFormat(my_fmt); myTF.embedFonts = true; myTF.html = true; myTF.cIndex = -1; myTF._alpha = 0; var formatText = function (myTF) { for (var x = 0; x<myTF.text.length; x++) { var c_fmt = myTF.getTextFormat(x, x+1); if (c_fmt.bold && c_fmt.italic) { c_fmt.font = myTF.fonts.bold_italic; } else if (c_fmt.bold) { c_fmt.font = myTF.fonts.bold; } else if (c_fmt.italic) { c_fmt.font = myTF.fonts.italic; } else { c_fmt.font = myTF.fonts.normal; } myTF.setTextFormat(x, c_fmt); } }; var tickerIt = function (myTF) { if (myTF._alpha<=0) { myTF.dir = 1; myTF.cIndex = (myTF.cIndex+1)%myTF.ticker.length; myTF.htmlText = myTF.ticker[myTF.cIndex]; formatText(myTF); } if (myTF._alpha>=100) { myTF.dir = -1; } myTF._alpha += myTF.dir; }; myTF.tickerID = setInterval(tickerIt, 1, myTF); }; TextField.prototype.pauseTicker = function() { clearInterval(this.tickerID); }; TextField.prototype.resumeTicker = function() { var myTF = this; var formatText = function (myTF) { for (var x = 0; x<myTF.text.length; x++) { var c_fmt = myTF.getTextFormat(x, x+1); if (c_fmt.bold && c_fmt.italic) { c_fmt.font = myTF.fonts.bold_italic; } else if (c_fmt.bold) { c_fmt.font = myTF.fonts.bold; } else if (c_fmt.italic) { c_fmt.font = myTF.fonts.italic; } else { c_fmt.font = myTF.fonts.normal; } myTF.setTextFormat(x, c_fmt); } }; var tickerIt = function (myTF) { if (myTF._alpha<=0) { myTF.dir = 1; myTF.cIndex = (myTF.cIndex+1)%myTF.ticker.length; myTF.htmlText = myTF.ticker[myTF.cIndex]; formatText(myTF); } if (myTF._alpha>=100) { myTF.dir = -1; } myTF._alpha += myTF.dir; }; myTF.tickerID = setInterval(tickerIt, 1, myTF); }; Then, on another layer, name it Actions, add the following code: //You do not have to use this dynamically made textfield! You can place your own one on the Stage. //And then add whatever properties you want here. Finally, change all the "myTF"s into whatever //instance name you gave your textfield. this.createTextField("myTF", this.getNextHighestDepth(), 0, Stage.height/2-10, Stage.width, 0); myTF.autoSize = 'center'; myTF.fonts = {normal:'norm_f', bold:'bold_f', italic:'italic_f', bold_italic:'bold_italic_f'}; myXML = new XML(); myXML.ignoreWhite = true; myXML.load('ticker.xml'); myXML.onLoad = function(success){ if(success){ myTF.ticker = new Array(); for(var x=0;x<myXML.firstChild.childNodes.length;x++){ myTF.ticker.push(myXML.firstChild.childNodes[x].childNodes.join('')); } myTF.addTicker(); }else{ trace('Could not load the specified file...'); } } //Code for pausing and playing _root.onMouseDown = function(){ _root.x = ((_root.x==undefined)? 0:x+1)%2; if(_root.x){ myTF.resumeTicker(); }else{ myTF.pauseTicker(); } } Embed the fonts for the different combinations like I said before (ie: normal, bold, italic, and bold/italic), but this time, give them the following linkage identifiers: norm_f, bold_f, italic_f, and bold_italic_f. Save this file. Then create a file, called ticker.xml, with the following text: <tickers> <ticker>Press the mouse to stop this ticker at <u>any</u> time</ticker> <ticker>Then press the mouse again to resume this ticker!</ticker> <ticker>1. <b>Hi, & welcome!</b><i> Put any text you want!</i></ticker> <ticker>2. <i>Enjoy the site</i><u> It works great!</u></ticker> <ticker>3. <u>Please look around!</u><b> Enjoy, enjoy!</b></ticker> <ticker>4. <b><i><u>Give me some feedback!</u></i></b></ticker> </tickers>
Don't see what you're looking for? Try a search.
|