Groups | Blog | Home
all groups > flash data integration > september 2005 >

flash data integration : Trouble with LoadVars


jd222
9/20/2005 12:00:00 AM
I am creating an application using Flash and ASP.NET. I have had no problem
connecting my ASP.NET pages with Flash but once the String reaches Flash in the
onLoad event/function it will not decode the string. I tried overriding the
onData event/function and calling the decode method directly and it decodes
fine which I verified through a trace statement. The problem is once it
reaches OnLoad it is as if it encodes again. Any help would be greatly
appreciated.

Here is my AS:
on(load) {
var getCategoryI:LoadVars = new LoadVars();
var checkCategoryI:LoadVars = new LoadVars();

getCategoryI.Category = "Category I"
getCategoryI.sendAndLoad("getCategory.aspx", getCategoryI, "POST");

getCategoryI.onData = function(stringa) {
trace(">> " + getCategoryI.httpStatusType + ": " +
getCategoryI.httpStatus);
if (stringa == undefined ) {
this.onLoad(false);
} else {
var run:LoadVars = new LoadVars();
getCategoryI.decode(stringa);
getCategoryI.onLoad(true);
}
}

getCategoryI.onLoad = function (success:Boolean)
{
if (success) {
trace(getCategoryI);
mx.controls.Alert.show("OK", "Admin", mx.controls.Alert.OK);
var courseCat:Array = getCategoryI.courseType.split("|");
var courseDate:Array = getCategoryI.courseDate.split("|");
var courseLoc:Array = getCategoryI.courseLocation.split("|");
var courseFee:Array = getCategoryI.fee.split("|");
var courseExam:Array = getCategoryI.exam.split("|");

var counter = 0;
var courseArray:Array = new Array();
while (counter < courseCat.length - 1)
{
courseArray[counter] = {Course_Category: courseCat[counter], Course_Date:

courseDate[counter], Course_Location: courseLoc[counter], Fee:
courseFee[counter], Exam: courseExam[counter]};
counter++;
}
_root.grid1.dataProvider = courseArray;
this.SetEditable = true;
this.getColumnAt(0).editable = false;
this.sortableColumns = false;
}else{
mx.controls.Alert.show("Error", "Admin", mx.controls.Alert.OK);
}
};




}
SimonTheSwift
9/21/2005 12:00:00 AM
Hi there,

ok, I do not know about ASP.NET, but when I send some data to Flash using PHP,
LoadVars always expects that data to be URL encoded (Example:
varialbe1=value1&variable2=value2...). So, make sure your ASP.NET script is
sending the message to LoadVars URL encoded. In PHP there is a function to do
this - urlencode().

Good luck,

Simon.
SimonTheSwift
9/21/2005 12:00:00 AM
Hi again,

I am sorry. I just realized that URL encoded is a bit different.

Let's say your script performs a calculation of a time difference. This is the
result you want to send to Flash:

time difference = 2 hours

To be able to acces it through LoadVars, you will have to pass it as a
variable and URL encoded. The data flowing from you script to Flash will look
like this:

TDResult=time+difference+%3D+2+hours

In this example, TDResult is a variable used to pass the answer from your
script to Flash. In Flash, you will be able to access the string like this:

var myVar:LoadVars = new LoadVars();
myVars.load(your URL);
myVars.onLoad = function() {
var myString:String = new String();
myString = myVar.TDResult;
trace(myString);
}
What I showed in the previous post was how to store data in an external file
accessed by Flash.

Simon
AddThis Social Bookmark Button