Return to Snippet

Revision: 4569
at January 9, 2008 16:52 by discorax


Initial Code
var bits:Array = new Array();

function addHtmlTag(tf:MovieClip,indexStart:Number,indexEnd:Number,tag:String):String{
	bits = new Array();
	bits = getStringParts(tf,indexStart,indexEnd);
    if(bits != undefined){
    var newString:String = bits[0] + " <" + tag + ">" + bits[1] + " </" + tag + ">" + bits[2];
	return newString;
	}
  }
  
function getStringParts(tf:MovieClip,indexStart:Number,indexEnd:Number):Array{
		var wholeString:String = tf.htmlText;
		var totalIndex:Number = wholeString.length;
		bits.push(wholeString.substring(0,indexStart));
		bits.push(wholeString.substring(indexStart,indexEnd));
		bits.push(wholeString.substring(indexEnd,totalIndex));
		//trace("bits: "+bits);
		return bits;
}

// usage
// var newText:String = addHtmlTag(myTextField_mc, 0, 10, "b");

Initial URL


Initial Description
This is a handy little function that takes the htmlText value of a TextField and ads a specified tag at the beginning and end of the string. Handy for quick formatting tags such as bold, italic, underline,  but could be used to add complex style data as it takes any string value.

Initial Title
add HTML tag to a string

Initial Tags
actionscript, html

Initial Language
ActionScript