Need Assistance Parsing Variables from another Web Site

Parsing variables from another web page with ActionScript 1.0

Page 1 of 1

2 Replies - 1421 Views - Last Post: 07 June 2007 - 11:45 AM

#1 xlivegamingx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-May 07

Need Assistance Parsing Variables from another Web Site

Post icon  Posted 25 May 2007 - 10:40 AM

I have been having this problem with parsing some variables from another website into a flash movie. Below is the actionscript that I currently am using. But it comes up with a error that says NaN and does not display the correct variable outputs from the other site. The information that I am tryin to get, or the variables that I am parsing into the flash movie, comes from http://www.bungie.ne...ayer=Enzo+Mafia. The ?player=Enzo+Mafia is the name of the account or profile that is on that site. The variables that I want to parse is displayed on that page at the very bottom, under Overview of Ranked Playlists. The variables should display a number between 1 and 50 or "No Games Played". Also there is some other info that is displayed on one page too. The next thing that should be parsed is the Clan variables. Which can be found on http://www.bungie.ne...er=Enzo%20Mafia page and also the variables that display the number between 1 and 50 or "No Games Played" are on http://www.bungie.ne...an=xlivegamingx page. Also on http://www.bungie.ne...er=Enzo%20Mafia there is an RSS feed that is displayed on another button of the flash movie, that displays the last 25 games. Everything for this flash file and php script and xml documentation and stuff is all located on http://stats.xlgx.net for refrence. For testing purposes anyone can use http://stats.xlgx.ne...me=Enzo%20Mafia to test out the flash movie that displays the stats. Also for the flash movie to display just the clan only http://stats.xlgx.ne...me=xlivegamingx which does not work and displays a invalid transmission error. If anyone can help then please do. Because i have no clue how to fix this problem anymore. THANKS.

// original script written by Marshall Beachy
// marshdabeachy@gmail.com
// Last Update: March 20, 2007
var address = this._url.split("?");
folder = address[0].split("/");
folder = folder.splice(0, folder.length-1).join("/");
phpScript = folder+"/stats.php";
if (address[0].substr(0, 5) == "file:") {
	// local testing, provide default name
	playerName = "dilinator";
	phpScript = "http://www.stats.xlgx.net/stats.php";
}
if (color1 == undefined) {
	color1 = 0xFFFFFF;
} else {
	color1 = parseInt(color1);
}
if (color2 == undefined) {
	color2 = 0x999999;
} else {
	color2 = parseInt(color2);
}
header.lineStyle(1, color2);
header.moveTo(0, 25);
header.lineTo(390, 25);
header.name.textColor = color1;
header.swapDepths(1);
totalBGs = 16;
triesLeft = 3;
xmlTries = 3;
fieldHeight = 8.5;
format = new TextFormat();
format.font = "Arial";
format.color = color1;
format.size = 10;
exp = new TextFormat();
exp.font = "Verdana";
exp.color = color2;
exp.size = 8;
createEmptyMovieClip("bgHold", 0);
if (bg == undefined || bg<1 || bg>totalBGs) {
	bg = random(totalBGs)+1;
} else if (bg.length>4) {
	bgHold.loadMovie(bg+".jpg");
}
if (!isNaN(bg) && bg>=1 && bg<=totalBGs) {
	bgHold.loadMovie(folder+"/stats"+bg+".jpg");
}
this.onEnterFrame = function() {
	if (bgHold.getBytesLoaded()/bgHold.getBytesTotal()>=1 && bgHold.getBytesTotal()>10) {
		var ratio = 400/120;
		if (bgHold._width/bgHold._height>ratio && bgHold._width>400) {
			bgHold._width = 400;
			bgHold._yscale = bgHold._xscale;
		} else if (bgHold._height>120) {
			bgHold._height = 120;
			bgHold._xscale = bgHold._yscale;
		}
		bgHold._x = 200-bgHold._width/2;
		bgHold._y = 60-bgHold._height/2;
		delete this.onEnterFrame;
		bgHold._alpha = 0;
		this.onEnterFrame = function() {
			bgHold._alpha += 5;
			if (bgHold._alpha>=100) {
				delete this.onEnterFrame;
			}
		};
	}
};
preLoad();
function preLoad() {
	if (clanName == undefined) {
		filename = "/Account/Profile.aspx?player="+escape(playerName);
	} else {
		if (playerName != undefined) {
			playerNameReserve = playerName;
		}
		playerName = clanName;
		filename = "/Account/Profile.aspx?clan="+escape(playerName);
	}
	if (playerName != undefined) {
		loadData();
	} else {
		header.name.text = "Please provide a name to load.";
	}
}
function loadData() {
	header.name.text = "Loading "+playerName+"...";
	htmlLoad = new LoadVars();
	htmlLoad.rand = random(99999);
	htmlLoad.filename = filename;
	htmlLoad.sendAndLoad(phpScript, htmlLoad, "POST");
	htmlLoad.onload = function(success) {
		if (success) {
			var str = unescape(this.file);
			scores = [];
			var pos = 0;
			var lastFind = 0;
			// find emblem
			var index1 = str.indexOf("halo2emblem.ashx", 0);
			if (index1 != -1) {
				var index2 = str.indexOf("\"", index1);
				var emblem = "http://www.bungie.net/Stats/"+str.substr(index1, index2-index1).split("&amp;").join("&");
				createEmptyMovieClip("emblemHold", 5);
				emblemHold.createEmptyMovieClip("container", 0);
				emblemHold.container.loadMovie(emblem);
				emblemHold.finished = false;
				emblemHold.onEnterFrame = function() {
					if (this.container.getBytesLoaded()/this.container.getBytesTotal() == 1 && !this.finished) {
						this._x = 22;
						this._y = 5;
						this._height = 20;
						this._xscale = this._yscale;
						this.finished = true;
						this._alpha = 0;
					} else if (this.finished) {
						this._alpha += 10;
						header.name._x += (this._x+this._width-header.name._x)*.3;
						if (this._alpha>=100) {
							header.name._x = this._x+this._width;
							delete this.onEnterFrame;
						}
					}
				};
			}
			var index = 0;
			while (index != -1) {
				var index = str.indexOf("ctl00_mainContent_statOverviewh2_dlHopperRanks_", lastFind);
				if (index != -1) {
					var safeCheck = str.indexOf(">", index);
					var isSafe = str.substr(index+29, safeCheck-index-30);
					if (isSafe.indexOf("lblNoLevel") == -1) {
						// game name
						var index1 = str.indexOf(">", index);
						var index2 = str.indexOf("<", index1);
						var gameMode = str.substr(index1+1, index2-index1-1);
						// level
						var checkNext = str.indexOf("div class=\"ExpBar\"", index);
						var checkNext = str.indexOf(">", checkNext+1)+2;
						if (checkNext>index2+100) {
							// no games played; skip out
							lastFind = index+1;
							continue;
						}
						// level found
						var index1 = str.indexOf(">", checkNext);
						var index2 = str.indexOf("<", index1+1);
						var level = Number(str.substr(index1+1, index2-index1-1));
						// experience
						var index1 = str.indexOf("width", index2);
						var index1 = str.indexOf("\"", index1);
						var index2 = str.indexOf("\"", index1+1);
						var experience = Number(str.substr(index1+1, index2-index1-1))/50;
						// games played
						var index1 = str.indexOf("<td>", index2);
						var index1 = str.indexOf(">", index1);
						var index2 = str.indexOf("<", index1);
						var gamesPlayed = Number(str.substr(index1+1, index2-index1-1));
						// wins
						var index1 = str.indexOf("<td>", index2);
						var index1 = str.indexOf(">", index1);
						var index2 = str.indexOf("<", index1);
						var gamesWon = Number(str.substr(index1+1, index2-index1-1));
						// percent
						var winPercent = roundTo(gamesWon/gamesPlayed*100, 1)+"%";
					} else {
						// no level found
						var level = "No Games Played";
						var gamesPlayed = "-";
						var gamesWon = "-";
						var experience = -1;
						var winPercent = "-";
					}
					scores[pos] = [gameMode, level, gamesPlayed, gamesWon, winPercent, experience];
					lastFind = index+1;
					pos++;
				} else {
					if (scores.length == 0) {
						// error loading
						if (str.indexOf("offline for maintenance.", 0) != -1 || str.indexOf("report this bug", 0) != -1 || str.indexOf("to you or your mom", 0) != -1) {
							header.name.text = playerName+" (stats offline)";
						} else if (str.indexOf("Internal Server Error", 0) != -1) {
							header.name.text = playerName+" (bungie.net internal server error)";
						} else if (str.indexOf("We don't have stats") != -1) {
							header.name.text = playerName+" (stats not found)";
						} else {
							triesLeft--;
							if (triesLeft>0) {
								loadData();
							} else {
								header.name.text = playerName+" (invalid transmission)";
							}
						}
					} else {
						displayGeneral(clanName == undefined ? 0 : 1);
					}
					break;
				}
			}
			if (clanName == undefined) {
				var index1 = str.indexOf("Clan: ", 0);
				if (index1 != -1) {
					var index1 = str.indexOf(">", index1)+1;
					var index2 = str.indexOf("<", index1);
					header.changeClan.clanName = str.substr(index1, index2-index1);
					header.changeClan.nextFrame();
				}
			}
		} else {
			header.name.text = playerName+" (error loading PHP file)";
		}
	};
	recentLoaded = false;
}
function loadXML() {
	var pName = playerNameReserve == undefined ? playerName : playerNameReserve;
	header.name.text = "Loading "+pName+" RSS...";
	xmlLoad = new LoadVars();
	xmlLoad.rand = random(99999);
	xmlLoad.filename = "/Stats/halo2rss.ashx?g="+escape(pName);
	xmlLoad.sendAndLoad(phpScript, xmlLoad, "POST");
	xmlLoad.onload = function(success) {
		if (success) {
			var pName = playerNameReserve == undefined ? playerName : playerNameReserve;
			recentLoaded = true;
			XML.prototype.ignoreWhite = true;
			var temp = unescape(this.file);
			var rssFeed = new XML(temp.substr(1, temp.length-1));
			var rss = rssFeed.childNodes[1].firstChild.childNodes;
			gameList = [];
			for (var m = 0; m<rss.length; m++) {
				if (rss[m].nodeName == "item") {
					var item = rss[m].childNodes;
					for (var n = 0; n<item.length; n++) {
						if (item[n].nodeName == "title") {
							var title = item[n].firstChild.nodeValue;
						} else if (item[n].nodeName == "pubDate") {
							var pubDate = item[n].firstChild.nodeValue;
						} else if (item[n].nodeName == "guid") {
							var guid = item[n].firstChild.nodeValue;
						} else if (item[n].nodeName == "description") {
							var game = item[n].firstChild.nodeValue.split("<br/>");
							if (gameHeaders == undefined) {
								gameHeaders = game[5].split("</b>")[0].split(": ");
								gameHeaders = gameHeaders[1].split(", ");
							}
							var gamePlayers = game.join("<br/>");
							var playerUpper = pName.toUpperCase();
							gamePlayers = gamePlayers.toUpperCase();
							var index1 = gamePlayers.indexOf(playerUpper, 0);
							if (index1 != -1) {
								var index1 = gamePlayers.indexOf(":", index1);
								var index2 = gamePlayers.indexOf("<", index1);
								var score = gamePlayers.substr(index1+2, index2-index1-2).split(", ");
								gameList.push([score, title+" ("+pubDate+")", guid]);
							} else {
								// playername not found, breaking out
								break;
							}
						}
					}
				}
			}
			if (gameList.length>0) {
				header.name.text = pName;
				displayMatches();
			} else {
				xmlTries--;
				if (xmlTries>0) {
					loadXML();
				} else {
					header.name.text = "RSS load failed.";
					delete xmlLoad;
				}
			}
		}
	};
}
function displayGeneral(num) {
	createEmptyMovieClip("general"+num, 2+num);
	if (num == 0) {
		header.changePlayer.gotoAndStop(2);
		header.changeRSS.gotoAndStop(2);
	} else if (num == 1) {
		header.changeClan.gotoAndStop(2);
	}
	var levelTotal = 0;
	var gamesTotal = 0;
	var winsTotal = 0;
	for (var j = 0; j<scores.length; j++) {
		if (scores[j][1] != "No Games Played") {
			// stats found
			levelTotal += scores[j][1]+scores[j][5];
			gamesTotal += scores[j][2];
			winsTotal += scores[j][3];
		} else {
			// use level 1 instead
			levelTotal += 1;
		}
	}
	var levelAvg = Math.floor(levelTotal/scores.length);
	var remainingExp = (levelTotal/scores.length)-levelAvg;
	var winPercent = roundTo(winsTotal/gamesTotal*100, 1);
	if (isNaN(winPercent)) {
		winPercent = "0.00";
	}
	scores.push([":: Total", levelAvg, gamesTotal, winsTotal, winPercent+"%", remainingExp]);
	var temp = general0.goal;
	if (temp == undefined) {
		temp = 0;
	}
	if (temp == num*-400 || clanName != undefined) {
		header.name.text = playerName;
		if (num == 1) {
			header.changeClan.nameHold = playerName;
		}
	}
	var headers = ["Playlist", "Level", "Played", "Wins", "Win %", "Experience"];
	var headersStart = [5, 90, 250, 305, 350, 400];
	this["general"+num].createEmptyMovieClip("barHold", 2);
	this["general"+num].createEmptyMovieClip("scoreHold", 3);
	for (var j = 0; j<=scores.length; j++) {
		var clip = this["general"+num].scoreHold.createEmptyMovieClip("row"+j, j);
		clip._y = 25+j*fieldHeight;
		for (var r = 0; r<headers.length; r++) {
			if (r != headers.length-1) {
				clip.createTextField("label"+r, r, headersStart[r], 0, headersStart[r+1]-headersStart[r], 18);
				clip["label"+r].setNewTextFormat(format);
				clip["label"+r].selectable = false;
				if (j == 0) {
					clip["label"+r].textColor = color2;
					clip["label"+r].text = headers[r];
				} else {
					clip["label"+r].text = scores[j-1][r];
				}
			} else if (j>0 && scores[j-1][r] != -1) {
				var bar = createBar(this["general"+num], headersStart[2]-headersStart[1]-30, fieldHeight-1, scores[j-1][r], j);
				bar._x = headersStart[1];
				bar._y = clip._y+5;
			}
		}
	}
}
function displayMatches() {
	header.changeRSS.gotoAndStop(2);
	for (var j = 0; j<gameList.length; j++) {
		for (var r = 0; r<gameList[j][0].length; r++) {
			if (j == 0) {
				this["sum"+(r+1)] = 0;
			}
			if (r == 0) {
				// non-numeric (1ST, 2ND, 3RD, etc)
				var num = parseInt(gameList[j][0][r]);
			} else {
				var num = Number(gameList[j][0][r])
			}
			this["sum"+(r+1)] += num;
		}
	}
	gameHeaders.unshift("");
	var lngth = gameHeaders.length;
	gameHeaders[lngth] = gameHeaders[lngth-1];
	gameHeaders[lngth-1] = "K/D Ratio";
	createEmptyMovieClip("matches", 4);
	matches._x = general0._x+800;
	matches.createTextField("header", 9999, 5, 26, 390, 20);
	matches.header.setNewTextFormat(format);
	matches.header.selectable = false;
	matches.header.text = "Total Recent Matches: "+gameList.length;
	for (var j = 0; j<3; j++) {
		var clip = matches.createEmptyMovieClip("row"+j, j);
		clip._y = 40+j*12;
		for (var r = 0; r<gameHeaders.length; r++) {
			clip.createTextField("label"+r, r, 5+(r/gameHeaders.length*390), 0, 100, 20);
			clip["label"+r].setNewTextFormat(format);
			clip["label"+r].selectable = false;
			if (j == 0) {
				// headers
				clip["label"+r].text = gameHeaders[r];
			} else if (j == 1) {
				// totals
				if (r == 0) {
					clip["label"+r].text = "Total";
				} else if (r == 1) {
					clip["label"+r].text = "-";
				} else if (r == lngth-1) {
					clip["label"+r].text = roundTo(sum3/sum4, 2);
				} else if (r == lngth) {
					clip["label"+r].text = this["sum"+(r-1)];
				} else {
					clip["label"+r].text = this["sum"+r];
				}
			} else if (j == 2) {
				// per game
				if (r == 0) {
					clip["label"+r].text = "Avg/Game";
				} else if (r == 1) {
					var places = ["ST", "ND", "RD"];
					var avgPlace = Math.round(this["sum"+r]/gameList.length);
					clip["label"+r].text = avgPlace+(avgPlace-1<places.length ? places[avgPlace-1] : "TH");
				} else if (r == lngth-1) {
					clip["label"+r].text = roundTo(sum3/sum4, 2);
				} else if (r == lngth) {
					clip["label"+r].text = roundTo(this["sum"+(r-1)]/gameList.length, 2);
				} else {
					clip["label"+r].text = roundTo(this["sum"+r]/gameList.length, 2);
				}
			}
		}
	}
	matches.matchNum = 0;
	matches.createEmptyMovieClip("matchDetail", 9997);
	matches.matchDetail._y = 76;
	matches.matchDetail.attachMovie("matchChange", "matchChange", 9999);
	matches.matchDetail.matchChange._x = 5;
	for (var j = 0; j<gameHeaders.length; j++) {
		matches.matchDetail.createTextField("label"+j, j, 5+(390/gameHeaders.length)+(j/gameHeaders.length*390), 0, 100, 20);
		matches.matchDetail["label"+j].setNewTextFormat(format);
		matches.matchDetail["label"+j].selectable = false;
	}
	matches.createTextField("matchView", 9996, 5, 88, 390, 20);
	matches.matchView.setNewTextFormat(format);
	matches.matchView.selectable = false;
	matches.createEmptyMovieClip("guid", 9995);
	matches.guid.createTextField("label", 0, 5, 100, 100, 20);
	matches.guid.label.setNewTextFormat(format);
	matches.guid.label.text = "- Launch full game stats";
	matches.guid.label.selectable = false;
	matches.guid.label.autoSize = true;
	matches.guid.onRelease = function() {
		getURL(this.guidURL, "_blank");
	};
	matches.guid.onRollOver = function() {
		this.label.textColor = color2;
	};
	matches.guid.onRollOut = function() {
		this.label.textColor = color1;
	};
	matches.matchDetail.matchChange.matchNum.textColor = color1;
	fillMatch();
}
function fillMatch() {
	matches.matchDetail.matchChange.matchNum.text = "Match #"+(matches.matchNum+1);
	matches.matchView.text = gameList[matches.matchNum][1];
	for (var j = 0; j<gameHeaders.length-1; j++) {
		if (j == 4) {
			var loses = Number(gameList[matches.matchNum][0][3]);
			if (loses == 0) {
				matches.matchDetail["label"+j].text = "-";
			} else {
				matches.matchDetail["label"+j].text = roundTo(Number(gameList[matches.matchNum][0][2])/loses, 2);
			}
		} else if (j == 5) {
			matches.matchDetail["label"+j].text = gameList[matches.matchNum][0][j-1];
		} else {
			matches.matchDetail["label"+j].text = gameList[matches.matchNum][0][j];
		}
	}
	matches.guid.guidURL = gameList[matches.matchNum][2];
}
function createBar(path, width, height, percent, depth) {
	var clip = path.barHold.createEmptyMovieClip("bar"+depth, depth);
	clip.createEmptyMovieClip("blank", 1);
	var offset = (percent == 0) ? 0 : 1;
	var round = 5;
	var endRound = round;
	if ((width*percent)/2<round) {
		round = (width*percent)/2;
	}
	with (clip.blank) {
		beginFill(color1, 15);
		moveTo(width*percent+offset-round, 0);
		lineTo(width-endRound, 0);
		curveTo(width, 0, width, endRound);
		lineTo(width, height-endRound);
		curveTo(width, height, width-endRound, height);
		lineTo(width*percent+offset-round, height);
		curveTo(width*percent+offset, height, width*percent+offset, height-round);
		lineTo(width*percent+offset, round);
		curveTo(width*percent+offset, 0, width*percent+offset-round, 0);
		endFill();
	}
	clip.blank.createTextField("label", 0, width, -3, 100, 20);
	clip.blank.label.setNewTextFormat(exp);
	clip.blank.label.text = Math.round(percent*100)+"%";
	clip.blank.label.selectable = false;
	clip.blank.label.autoSize = true;
	clip.createEmptyMovieClip("bar", 0);
	with (clip.bar) {
		var matrix = {matrixType:"box", x:0, y:0, w:width*percent, h:height, r:0};
		beginGradientFill("linear", [color1, color1, color1], [20, 35, 45], [0, 220, 255], matrix);
		moveTo(0, round);
		curveTo(0, 0, round, 0);
		lineTo(width*percent-round, 0);
		curveTo(width*percent, 0, width*percent, round);
		lineTo(width*percent, height-round);
		curveTo(width*percent, height, width*percent-round, height);
		lineTo(round, height);
		curveTo(0, height, 0, height-round);
		endFill();
	}
	return clip;
}
function easeView(goal) {
	if (goal == 1) {
		header.name.text = clanName;
	} else {
		header.name.text = playerNameReserve == undefined ? playerName : playerNameReserve;
	}
	general0.goal = goal*-400;
	general0._visible = true;
	general1._visible = true;
	matches._visible = true;
	general0.onEnterFrame = function() {
		this._x += (this.goal-this._x)*.3;
		if (Math.abs(this._x-this.goal)<1) {
			this._x = this.goal;
			delete this.onEnterFrame;
			if (this.goal == 0) {
				general1._visible = false;
				matches._visible = false;
			} else if (this.goal == -400) {
				this._visible = false;
				matches._visible = false;
			} else {
				this._visible = false;
				general1._visible = false;
			}
		}
		general1._x = this._x+400;
		matches._x = this._x+800;
	};
}
function roundTo(num, digits) {
	if (digits<=0) {
		return Math.round(num);
	}
	var tenToPower = Math.pow(10, digits);
	var cropped = String(Math.round(num*tenToPower)/tenToPower);
	if (cropped.indexOf(".") == -1) {
		cropped += ".0";
	}
	var halves = cropped.split(".");
	var zerosNeeded = digits-halves[1].length;
	for (var i = 1; i<=zerosNeeded; i++) {
		cropped += "0";
	}
	return (cropped);
}



Also I have added this actionscript to http://stats.xlgx.net in the form of a text document.

Also I can not get in contact with the original maker of this actionscript for help. So I would really appreciate it if someone could assist me with it. Thanks!!!

This post has been edited by xlivegamingx: 25 May 2007 - 10:44 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Need Assistance Parsing Variables from another Web Site

#2 xlivegamingx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-May 07

Re: Need Assistance Parsing Variables from another Web Site

Post icon  Posted 26 May 2007 - 07:14 PM

Attached File  stats_Updated_2007.zip (131.14K)
Number of downloads: 71

Update --> Here is the full documentation and source code. Also note that http://stats.xlgx.net is no longer up. Thanks. And I posted again because I can no longer edit my previous post.
Was This Post Helpful? 0
  • +
  • -

#3 xlivegamingx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-May 07

Re: Need Assistance Parsing Variables from another Web Site

Posted 07 June 2007 - 11:45 AM

CAN ANYONE PLEASE HELP!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1