I have a preloader that is supposed to pass any FlashVars given to it to the SWF it is loading. Simple, right? It works dandy fine with Flash’s built-in Javascript embed. It sits there, twiddling its thumbs, if using SWFObject’s embed Javascript function.
It hangs whenever I assign the URLRequest.data to anything. If it is blank ("") or null, it works great. If I pass a non-empty string or URL variables, it just sits there and does nothing. There are no errors. I have tried a single key/value pair, fails. The browser just spins and the progress meter does not move. It is as if the URLRequest was never sent.
HTML with embed:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Rawr</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript">
function showFlashVarValues(postScoreURL, checkEmailURL, startGameURL, userID, userDetailID, gameSessionID, gamePlayID)
{
alert(postScoreURL);
}
function setCookie(name, value, expires)
{
// no expiration date specified? use this date and it will just be deleted soon.
if (!expires) expires = new Date();
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}
function setCookieFromFlash(userID)
{
var expdate = new Date (); // pre-set to the current time and date
expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 365); // add one year to it
//365 days/year * 24 hours/day * 60 minutes/hour * 60 seconds/minute * 1000 milliseconds/second
// = howevermany milliseconds/year. So this adds one year, it'll expire in one year.
setCookie("userID",userID,expdate);
}
//swfobject.embedSWF("Preloader_BB.swf", "flashHolder", "550", "400", "9.0.0", "expressInstall.swf");
var flashvars = {
postScoreURL: "http://games.rawr.com/rawr/postScore.asp",
checkEmailURL: "http://games.rawr.com/rawr/lookupByEmail.asp",
startGameURL: "http://games.rawr.com/rawr/startGame.asp",
userID: "0",
userDetailID: "0",
gameSessionID: "0",
gamePlayID: "0"
};
var params = {};
var attributes = {};
swfobject.embedSWF("Preloader_BB.swf", "flashHolder", "550", "400", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
</script>
</head>
<body bgcolor="#000000">
<div id="flashHolder">
<h1>This game requires Adobe Flash.</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
</body>
</html>
Actionscript: (The code block seems to break formatting)
try
{
stop();
var myRequest:URLRequest = new URLRequest("Stripped.swf");
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, LoadProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadComplete);
BeginLoading();
}
catch (e:Error)
{
txtError.text = e.message;
}
function BeginLoading():void
{
txtError.appendText("begun loading...
");
myRequest.method = URLRequestMethod.POST;
var variables:URLVariables = GetObjectVariables(this.root.loaderInfo.parameters);
if (variables != null)
{
myRequest.data = variables; //GetObjectVariables(this.loaderInfo.parameters);
txtError.appendText("data = '" + myRequest.data.toString() + "'
");
}
myLoader.load(myRequest);
}
function LoadProgress(event:ProgressEvent):void
{
var percentLoaded:Number = event.bytesLoaded / event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
txtLoading.text = "Loading... " + percentLoaded + "%";
txtError.appendText("Loading: " + percentLoaded + "%
");
}
function LoadComplete(event:Event):void
{
txtError.appendText("Complete
");
this.visible = false;
this.parent.addChild(event.currentTarget.content);
event.currentTarget.content.Initialize();
}
function GetObjectVariables(object:Object):URLVariables
{
var variables:String = "";
var key:String;
var value:String;
for (key in object)
{
value = String(object[key]);
variables = variables + key + "=" + value + "&";
break;
}
var decoded:URLVariables = new URLVariables();
if (variables.length > 0)
{
decoded.decode(variables.substr(0, variables.length - 1));
}
return decoded;
//return variables.substr(0, variables.length - 1);
}
Flash and I have a hate-hate relationship! Only one will prevail.
EDIT:
I attached an event to listen for IO Errors, and I do receive one. But ONLY if I set the URLRequest.data to be anything. It appears URLRequest.data causes the IO error.
Why in the world is assigning some data via a POST in a URLRequest breaking the URL?!?
Cheers.