PDA

View Full Version : ColdFusion and LoadVars problem


retrotron
04-22-2003, 04:07 AM
Perhaps there is someone who knows a simple solution to my problem. I hope so, since my deadline is rapidly approaching.

When I use LoadVars.sendAndLoad() to gather the output from a .cfm file, the variables are not evaluated but rather are displayed in Flash as unevaluated ColdFusion variables (e.g. #myVariable#).

My varsData.cfm contains this code:

<cfset msg = "hello world!">
<cfoutput> &output=#msg#& </cfoutput>

My Flash has nothing but a large dynamic text box (named "results_txt") with a standard component button (named "load_btn"). The ActionScript reads:

// create a new LoadVars instance
thisVars = new LoadVars();

// load the variables when the button is clicked
load_btn.onRelease = function() {
// send thisVars to "varsData.cfm", put results in thisVars
thisVars.sendAndLoad("varsData.cfm", thisVars);
} // end onRelease function()

// swonking function
thisVars.onLoad = function(success) { // check if vars all loaded
if (success) { // vars completely loaded
trace("success");
formatText();
} else { // The data didn’t load at all. Display error
trace("error: data didn't load");
} // end "if (success)" statament
} // end swonking function

// set the text
function formatText() {
_root.results_txt.text = thisVars.output;
} // end formatText()

// stop the movie
stop();
When I test the movie and click the button, I get "#msg#" rather than "hello world!" displayed in the textfield. I obviously need #msg# to be evaluated to "hello world!". Can anyone shed some light on why this is happening and how I am to fix the problem?

Pax et bonum,
retrotron

PS. Someone told me this issue corrected by Macromedia is the solution: http://www.macromedia.com/support/flash/ts/documents/load_xdomain.htm. However, I am developing and testing all on a local machine, so it shouldn't have a problem with cross-domain interaction. Also, I don't think I understand the instructions at said site very well, they are too ambiguous for me.

freddycodes
04-23-2003, 01:30 AM
Your problem is fairly simple. When you test the movie from flash you are not using any web server, so the cfm file is not parsed. You either need to export the movie and view it on a server, or change the path in your sendAndLoad call to a full path like.


thisVars.sendAndLoad("http://localhost/varsData.cfm", thisVars);


What you were doing would be the same as using IE and doing a File > Open and finding the cfm file on the hard drive, and simply opening it, Cold Fusion never parse the CF code because you need the web server to do that.

retrotron
04-23-2003, 01:42 AM
Ah, a very clear answer. Thanks so much!