Skip to main content
Inspiring
June 2, 2006
Question

XML via sendAndLoad to and from coldfusion server

  • June 2, 2006
  • 6 replies
  • 366 views


Hello,



I'm working on this test that calls a coldfusion file server and
delivers a login data.

Then the server validates the information provided and if true returns a
xml data.

My problem is when using the sendAndLoad vars, on the onLoad I receive a
xml damaged? or String?.

Something like a query string result, text like "<" and ' " ' are
converted to html text "&lt;" and "&quot;".



This is my code:



//
///////////////////////////////////////////////////////////////////////////////////////////////
// LOAD XML

var loadFromServer:XML = new XML ();
loadFromServer.ignoreWhite = true;
//
///////////////////////////////////////////////////////////////////////////////////////////////


loadFromServer.onLoad = function (success:Boolean) {


if (success) {
trace(this)

// traces this:

//&lt;?xml version=&quot;1.0&quot;
encoding=&quot;iso-8859-1&quot;?&gt

// insted of this:

// <?xml version="1.0" encoding="iso-8859-1"?>
} else {
trace("error")

}
};


//
///////////////////////////////////////////////////////////////////////////////////////////////
// SEND
var sendToServer:LoadVars = new LoadVars ();
sendToServer.USER_ID = username;
sendToServer.USER_PASSWORD = userpassword;
sendToServer.sendAndLoad (" http://domain/login.cfm", loadFromServer,
"POST");



Is this a problem from:

Flash?

SendAndLoad with "POST"?

Server side?



Could some one help me please?



Thanks






This topic has been closed for replies.

6 replies

Inspiring
June 2, 2006
Hi again,



I think Francis Cheng example would off course never work.



/*

var arr:Array = new Array();
arr.foo = "foo";
arr.bar = "bar";
arr.push("foobar");
trace(arr.length); // output: 1

*/



I think that the Array method for accessing information, [], wille
developing is not to clear or you can say not so user friendly.



1.

id:Array = new Array (1, 2, 3);

name:Array = new Array ("John", "Michael", "Ana");



myArray:Array = new Array ( [ id[0], name[0] ], [ id[1], name[1] ],
[ id[2], name[2] ] );



trace( nameArray[0][0]);

trace( nameArray[0][1]);



Instead of:



2.

myArray:Array = new Array ();

myArray.push ({id:1, name:"John"});

myArray.push ({id:2, name:"Michael"});

myArray.push ({id:3, name:"Ana"});



trace (myArray[0].id)

trace (myArray[0].name)





As you see in example 2 I have the control of the list as an array but I
easily access information in a simpler and more understandable way.

This example works when you need to index a bunch of elements with
properties.

But I would use the 1 example to work the movements of a "tower" in a chess
game with key arrows. In this case information would be provided as rows and
columns:



[1] [2] [3] [4] [5] [6]

[7] [8] [9] [10] [11] [12]

[13] [14] [15] [16] [17] [18]



Regarding my xml problem: I did an example with a simple:



<?php
echo '<?xml version="1.0" encoding="iso-8859-1"?>
<jobQueueList>
<item min="45" hour="10" day="22" month="6"
year="2006">Content</item>
<item min="10" hour="18" day="23" month="6"
year="2006">Content</item>
<item min="0" hour="11" day="22" month="6"
year="2006">Content</item>
<item min="23" hour="17" day="23" month="6"
year="2006">Content</item>
<item min="20" hour="18" day="23" month="6"
year="2006">Content</item>
</jobQueueList>';
?>



...and flash received the code and recognize it as an object with xml
encoding.



Thanks anyway : (











"ImagicDigital" <> wrote in message
news:e5qcj9$j1$1@forums.macromedia.com...
> So are you returning more than one set of data at once? If not, you can
> push the values returned to your LoadVars object into an associative array
> just like you would XML values.
>
> var myList:Array = new Array ();
>
> loadFromServer.onLoad = function(success) {
> if (success) {
> myList.push ( {id: loadFromServer.userID, fname:
> loadFromServer.firstName, pass: loadFromServer.pass})
> } else {
> trace("error");
> }
> };
>
> Also, an associative array (what you have) is really just an object. As
> far as I understand (recent discussion here:
>
> http://groups.google.com/group/macromedia.flash.actionscript/browse_frm/thread/3fb84bf9d6220ee6/18b9a9ef5ff15c96
> )
>
> it doesn't have access to all of the Array class methods anyway. Or how
> are you manipulating it?
>
> SteveStall wrote:
>
>>
>> Normally I use xml in order to have control of length of information,
>> example populating a list.
>>
>> I can dynamically read the length/number of items in the returned object.
>>
>> What I do is load an xml and then in flash I organise the information
>> into a multidimensional array based on objects.
>>
>>
>>
>> var myList:Array = new Array ();
>>
>> myList.push ({ id:<id>, name:<name>, pass:<pass> ... });
>>
>> // <id>, <name>, <pass> are provided with the xml
>>
>>
>>
>> This gives me the power to manipulate information with all the utilities
>> that Array Class provides. Sorting, shift, shuffle...
>
>>


Inspiring
June 2, 2006
So are you returning more than one set of data at once? If not, you can
push the values returned to your LoadVars object into an associative
array just like you would XML values.

var myList:Array = new Array ();

loadFromServer.onLoad = function(success) {
if (success) {
myList.push ( {id: loadFromServer.userID, fname:
loadFromServer.firstName, pass: loadFromServer.pass})
} else {
trace("error");
}
};

Also, an associative array (what you have) is really just an object. As
far as I understand (recent discussion here:

http://groups.google.com/group/macromedia.flash.actionscript/browse_frm/thread/3fb84bf9d6220ee6/18b9a9ef5ff15c96
)

it doesn't have access to all of the Array class methods anyway. Or how
are you manipulating it?

SteveStall wrote:

>
> Normally I use xml in order to have control of length of information,
> example populating a list.
>
> I can dynamically read the length/number of items in the returned object.
>
> What I do is load an xml and then in flash I organise the information into a
> multidimensional array based on objects.
>
>
>
> var myList:Array = new Array ();
>
> myList.push ({ id:<id>, name:<name>, pass:<pass> ... });
>
> // <id>, <name>, <pass> are provided with the xml
>
>
>
> This gives me the power to manipulate information with all the utilities
> that Array Class provides. Sorting, shift, shuffle...

>
Inspiring
June 2, 2006
Hi there,



- Is there a reason you're returning XML data instead of a structure of
variables?



Normally I use xml in order to have control of length of information,
example populating a list.

I can dynamically read the length/number of items in the returned object.

What I do is load an xml and then in flash I organise the information into a
multidimensional array based on objects.



var myList:Array = new Array ();

myList.push ({ id:<id>, name:<name>, pass:<pass> ... });

// <id>, <name>, <pass> are provided with the xml



This gives me the power to manipulate information with all the utilities
that Array Class provides. Sorting, shift, shuffle...

I know that with php you can serialize an xml into an array of objects and
deliver it to flash. I think it also safes pc memory avoiding flash to parse
xml.



//



By using your example, were the loadVars Class contains the information as
own objects, is it possible to control length of items?



Thanks
















"ImagicDigital" <> wrote in message
news:e5q30a$i7b$1@forums.macromedia.com...
> Is there a reason you're returning XML data instead of a structure of
> variables? Perhaps there is... if so, I'm interested to know. Unless
> you're logging in multiple people at once with this code, it might be
> easier to use a LoadVars object in Flash to catch all of the "keys" of
> that structure as properties of the LoadVars object. For example:
>
> Your cfm could return your info with something like this:
>
> <cfif qLogin.recordcount gt 0>
> <cfoutput query = "qLogin">
> &firstName = #FIRST_NAME#
> &lastName = #LAST_NAME#
> &userID = #USER_ID#
> </cfoutput>
> </cfif>
>
>
> Then in Flash, instead of an XML.onLoad, use LoadVars.onLoad, something
> like:
>
> var loadFromServer:LoadVars = new LoadVars();
> loadFromServer.onLoad = function(success) {
> if (success) {
> trace(loadFromServer.firstName);
> trace(loadFromServer.lastName);
> trace(loadFromServer.userID);
> // and maybe put into text boxes
> // assumes the dynamic text boxes already on stage
> firstName_txt.text = loadFromServer.firstName;
> lastName_txt.text = loadFromServer.lastName;
> userID_txt.text = loadFromServer.userID;
> } else {
> trace("error");
> error_txt.text = "There was an error loading the file.";
> }
> };
> //
> var sendToServer:LoadVars = new LoadVars();
> sendToServer.USER_ID = username;
> sendToServer.USER_PASSWORD = userpassword;
> sendToServer.sendAndLoad(" http://domain/login.cfm", loadFromServer,
> "POST");
>
>
>
> SteveStall wrote:
>> Hello,
>>
>>
>>
>> I'm working on this test that calls a coldfusion file server and
>> delivers a login data.
>>
>> Then the server validates the information provided and if true
>> returns a xml data.
>>
>> My problem is when using the sendAndLoad vars, on the onLoad I
>> receive a xml damaged? or String?.
>>
>> Something like a query string result, text like "<" and ' " ' are
>> converted to html text "&lt;" and "&quot;".
>>
>>
>>
>> This is my code:
>>
>>
>>
>> //
>> ///////////////////////////////////////////////////////////////////////////////////////////////
>> // LOAD XML
>>
>> var loadFromServer:XML = new XML ();
>> loadFromServer.ignoreWhite = true;
>> //
>> ///////////////////////////////////////////////////////////////////////////////////////////////
>>
>>
>> loadFromServer.onLoad = function (success:Boolean) {
>>
>>
>> if (success) {
>> trace(this)
>>
>> // traces this:
>>
>> //&lt;?xml version=&quot;1.0&quot;
>> encoding=&quot;iso-8859-1&quot;?&gt
>>
>> // insted of this:
>>
>> // <?xml version="1.0" encoding="iso-8859-1"?>
>> } else {
>> trace("error")
>>
>> }
>> };
>>
>>
>> //
>> ///////////////////////////////////////////////////////////////////////////////////////////////
>> // SEND
>> var sendToServer:LoadVars = new LoadVars ();
>> sendToServer.USER_ID = username;
>> sendToServer.USER_PASSWORD = userpassword;
>> sendToServer.sendAndLoad (" http://domain/login.cfm", loadFromServer,
>> "POST");
>>
>>
>>
>> Is this a problem from:
>>
>> Flash?
>>
>> SendAndLoad with "POST"?
>>
>> Server side?
>>
>>
>>
>> Could some one help me please?
>>
>>
>>
>> Thanks
>>
>>
>>
>>
>>

Inspiring
June 2, 2006
I there, to be honest I really don't know the difference.

"I tried" <webforumsuser@macromedia.com> wrote in message
news:e5q2ik$hmp$1@forums.macromedia.com...
> If you have a coldfusion server on the backend, wouldn't it be easier to
> use remoting rather than passing xml back and forth?


Inspiring
June 2, 2006
Is there a reason you're returning XML data instead of a structure of
variables? Perhaps there is... if so, I'm interested to know. Unless
you're logging in multiple people at once with this code, it might be
easier to use a LoadVars object in Flash to catch all of the "keys" of
that structure as properties of the LoadVars object. For example:

Your cfm could return your info with something like this:

<cfif qLogin.recordcount gt 0>
<cfoutput query = "qLogin">
&firstName = #FIRST_NAME#
&lastName = #LAST_NAME#
&userID = #USER_ID#
</cfoutput>
</cfif>


Then in Flash, instead of an XML.onLoad, use LoadVars.onLoad, something
like:

var loadFromServer:LoadVars = new LoadVars();
loadFromServer.onLoad = function(success) {
if (success) {
trace(loadFromServer.firstName);
trace(loadFromServer.lastName);
trace(loadFromServer.userID);
// and maybe put into text boxes
// assumes the dynamic text boxes already on stage
firstName_txt.text = loadFromServer.firstName;
lastName_txt.text = loadFromServer.lastName;
userID_txt.text = loadFromServer.userID;
} else {
trace("error");
error_txt.text = "There was an error loading the file.";
}
};
//
var sendToServer:LoadVars = new LoadVars();
sendToServer.USER_ID = username;
sendToServer.USER_PASSWORD = userpassword;
sendToServer.sendAndLoad(" http://domain/login.cfm", loadFromServer, "POST");



SteveStall wrote:
> Hello,
>
>
>
> I'm working on this test that calls a coldfusion file server and
> delivers a login data.
>
> Then the server validates the information provided and if true returns a
> xml data.
>
> My problem is when using the sendAndLoad vars, on the onLoad I receive a
> xml damaged? or String?.
>
> Something like a query string result, text like "<" and ' " ' are
> converted to html text "&lt;" and "&quot;".
>
>
>
> This is my code:
>
>
>
> //
> ///////////////////////////////////////////////////////////////////////////////////////////////
> // LOAD XML
>
> var loadFromServer:XML = new XML ();
> loadFromServer.ignoreWhite = true;
> //
> ///////////////////////////////////////////////////////////////////////////////////////////////
>
>
> loadFromServer.onLoad = function (success:Boolean) {
>
>
> if (success) {
> trace(this)
>
> // traces this:
>
> //&lt;?xml version=&quot;1.0&quot;
> encoding=&quot;iso-8859-1&quot;?&gt
>
> // insted of this:
>
> // <?xml version="1.0" encoding="iso-8859-1"?>
> } else {
> trace("error")
>
> }
> };
>
>
> //
> ///////////////////////////////////////////////////////////////////////////////////////////////
> // SEND
> var sendToServer:LoadVars = new LoadVars ();
> sendToServer.USER_ID = username;
> sendToServer.USER_PASSWORD = userpassword;
> sendToServer.sendAndLoad (" http://domain/login.cfm", loadFromServer,
> "POST");
>
>
>
> Is this a problem from:
>
> Flash?
>
> SendAndLoad with "POST"?
>
> Server side?
>
>
>
> Could some one help me please?
>
>
>
> Thanks
>
>
>
>
>
>
June 2, 2006
If you have a coldfusion server on the backend, wouldn't it be easier to use remoting rather than passing xml back and forth?