Monday, February 20, 2006

code

var messages = Array();

// load in XML
sms = new XML();
sms.ignoreWhite = true;
sms.onLoad = function(success) {
if (success) {
var arr;
txtone = "";
arr = sms.firstChild.firstChild.childNodes[1];
var flag = false;
var next = 0;
while (!flag) {
if (arr.childNodes[0].childNodes[5].nodeName != "false") {
flag = true;
txtone = arr.childNodes[0].childNodes[3].firstChild+"";
}
next++;
}
}

if (txtone.charAt(1) == ":") {
if (txtone.substring(0, 2) == "1:") {
txtone = removeHeader(txtone);
oneText.text = txtone;
} else if (txtone.substring(0, 2) == "2:") {
txtone = removeHeader(txtone);
twoText.text= txtone;
} else if (txtone.substring(0, 2) == "3:") {
txtone = removeHeader(txtone);
threeText.text = txtone;
} else if (txtone.substring(0, 2) == "4:") {
txtone = removeHeader(txtone);
fourText.text = txtone;
} else if (txtone.substring(0, 2) == "5:") {
txtone = removeHeader(txtone);
fiveText.text = txtone;
} else if (txtone.substring(0, 2) == "6:") {
txtone = removeHeader(txtone);
sixText.text = txtone;
} else if (txtone.substring(0, 2) == "7:") {
txtone = removeHeader(txtone);
sevenText.text = txtone;
} else if (txtone.substring(0, 2) == "8:") {
txtone = removeHeader(txtone);
eightText.text = txtone;
} else if (txtone.substring(0, 2) == "9:") {
txtone = removeHeader(txtone);
nineText.text = txtone;
}
} else {
trace("error");
}
}

onEnterFrame = function () {
sms.load("contents.plist");
};
function removeHeader(editString) {
//invoke new String obj called 'temp'
var temp = new String();
temp = editString.substring(2);
return cleanText(temp);
}

// cleans out quotes and apostrophes
function cleanText(pInString:String):String {

// if there is no entity in the string, then don't bother...
if (pInString == undefined || pInString == null || pInString.indexOf("&") == -1) {
return pInString;
} else {
// we replace all the entities with escaped versions of their strings
pInString = replace(pInString, """, "\u0022");
pInString = replace(pInString, "'", "\u0027");
}

// turns the escaped characters into items for Flash to display
return pInString;
}

//replaces one string with another in the supplied string
function replace (origStr:String, searchStr:String, replaceStr:String) {
var tempStr = "";
var startIndex = 0;
if (searchStr == "") {
return origStr;
}

if (origStr.indexOf(searchStr) == -1) {
return origStr;
} else {
var searchIndex = 0;
while ((searchIndex = origStr.indexOf(searchStr, startIndex)) != -1) {
tempStr += origStr.substring(startIndex, searchIndex);
tempStr += replaceStr;
startIndex = searchIndex + searchStr.length;
}

return tempStr + origStr.substring(startIndex);
}
}

0 Comments:

Post a Comment

<< Home