PDA

View Full Version : Flash MX 2004 remoting: Works on localhost, but not on web server


lespaul00
01-07-2008, 06:55 PM
Hello,

I’ve been working on developing a remote widget using flash remoting to my coldfusion server. I’ve gotten it to work properly on my localhost (http://localhost:8500/) but it does not work when I upload it to my website (www.mywebsite.com for example). The .swf looks right when I access it from my website, but fails to pull the information in from my coldfusion server and display it. Any help is GREATLY appreciated… this has been a long struggle.

For development, I am using:

Flash MX 2004 Professional
Dreamweaver 8
Coldfusion MX7

I took an example in Ben Forta’s book, Macromedia ColdFusion MX 7 Web Application Construction Kit, to use as a test for my flash remoting. As so, I have modified it a bit to suit my needs. I am simply having it retrieve and display an image and description (just for testing).

Below is a breakdown of my codes, and the directory locations of each of the files.

For localhost testing:

MerchBrowser.fla is located in C:\CFusionMX7\mywebsite\remoting\
MerchProviderCFC.cfc is located in C:\CFusionMX7\mywebsite\remoting\
MerchDetailProvider.cfm is located in C:\CFusionMX7\mywebsite\remoting\
MerchRecordsetProvider.cfm is located in C:\CFusionMX7\mywebsite\remoting\
Mydatabase.mdb is located in C:\CFusionMX7\mywebsite\db\

MerchBrowser.fla

// Include support for Flash Remoting Components
#include "NetServices.as"

// uncomment this line when you want to use the NetConnect debugger
// #include "NetDebug.as"

// --------------------------------------------------
// Handlers for user interaction events
// --------------------------------------------------

// --------------------------------------------------
// Application initialization
// --------------------------------------------------

if (inited == null)
{
// do this code only once
inited = true;

// set the default gateway URL (this is used only in authoring)
NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway")

// connect to the gateway
gateway_conn = NetServices.createGatewayConnection();

// get a reference to a service
// In this case, the "service" is the /ows/26 directory in web server root
myService = gateway_conn.getService("mywebsite.remoting.MerchProviderCFC", this);

// Call the service function that fills the ListBox with a list
// of products (from ColdFusion) for the user to browse through
myService.MerchDetailProvider();
}

// This function retrieves the detail information about the selected product.
// It is executed when the last frame of the movie is reached
// (when the detail view has finished hiding itself under the product list)


// --------------------------------------------------
// Handlers for data coming in from server
// --------------------------------------------------

// This executes when a merchandise detail record has been received
function MerchDetailProvider_Result(result) {
// The result variable is a recordset that contains just one row
// The detailRecord variable will represent the row of data
var detailRecord = result.getItemAt(0);

// Display detail information in text boxes

_root.DescriptionTextBox.text = detailRecord.MerchDescription;
loadMovie("../images/" + detailRecord.ImageNameSmall, _root.ImageMovie);

// If the ImageNameSmall column contains an image filename, display it

// Now that the information about the merchandise has been placed,
// make the display slide back into view, revealing the information

}

// Stop here, so animation doesn't occur until user selects a product
stop();



MerchProviderCFC.cfc

<!---
Filename: MerchProviderCFC.cfc
Author: Nate Weiss (NMW)
Purpose: Creates a ColdFusion Component that supplies data about products
--->

<cfcomponent hint="Provides data about merchandise records." output="false">


<!--- merchDetailProvider() function --->
<cffunction name="merchDetailProvider" returnType="query" access="remote"
hint="Returns details about a particular item in the Merchandise table."
output="false">



<cfset var merchQuery = "">

<!--- Query the database for merchandise records --->
<cfquery name="merchQuery" datasource=" Mydatabase.mdb" maxrows="1">
SELECT MerchID, MerchName, MerchDescription, ImageNameSmall, MerchPrice
FROM Merchandise
WHERE MerchID = 12
</cfquery>



<!--- Return the query --->
<cfreturn merchQuery>
</cffunction>

</cfcomponent>




MerchDetailProvider.cfm

<!---
Filename: MerchDetailProvider.cfm
Author: Nate Weiss (NMW)
Purpose: Provides film detail to a Flash movie
--->

<!--- We are expecting a MerchID parameter to be passed from Flash --->


<!--- Query the database for merchandise records --->
<cfquery name="MerchQuery" datasource="Mydatabase.mdb">
SELECT MerchID, MerchName, MerchDescription, ImageNameSmall, MerchPrice
FROM Merchandise
WHERE MerchID = 12
</cfquery>



<!--- This will be available as the “result” variable in the --->
<!--- MerchDetailProvider_Result handler within the Flash movie --->
<cfset FLASH.result = merchQuery>




MerchRecordsetProvider.cfm

<!---
Filename: MerchRecordsetProvider.cfm
Author: Nate Weiss (NMW)
Purpose: Provides data to a Flash MX movie
--->

<!--- Query the database for merchandise records --->
<cfquery name="merchQuery" datasource="Mydatabase.mdb">
SELECT MerchID, MerchName
FROM Merchandise
ORDER BY MerchName
</cfquery>

<!--- This will be available as the “result” variable in the --->
<!--- MerchRecordsetProvider_Result handler within the Flash movie --->
<cfset FLASH.result = merchQuery>



For website testing:

MerchBrowser.fla is located in http://www.mywebsite.com/remoting2/
MerchProviderCFC.cfc is located in http://www.mywebsite.com/remoting2/
MerchDetailProvider.cfm is located in http://www.mywebsite.com/remoting2/
MerchRecordsetProvider.cfm is located in http://www.mywebsite.com/remoting2/
Mydatabase.mdb is located in http://www.mywebsite.com/db/


MerchBrowser.fla

// Include support for Flash Remoting Components
#include "NetServices.as"

// uncomment this line when you want to use the NetConnect debugger
// #include "NetDebug.as"

// --------------------------------------------------
// Handlers for user interaction events
// --------------------------------------------------

// --------------------------------------------------
// Application initialization
// --------------------------------------------------

if (inited == null)
{
// do this code only once
inited = true;

// set the default gateway URL (this is used only in authoring)
NetServices.setDefaultGatewayUrl("http://www.mywebsite.com/flashservices/gateway")

// connect to the gateway
gateway_conn = NetServices.createGatewayConnection();

// get a reference to a service
// In this case, the "service" is the /ows/26 directory in web server root
myService = gateway_conn.getService("mywebsite.remoting2.MerchProviderCFC", this);

// Call the service function that fills the ListBox with a list
// of products (from ColdFusion) for the user to browse through
myService.MerchDetailProvider();
}

// This function retrieves the detail information about the selected product.
// It is executed when the last frame of the movie is reached
// (when the detail view has finished hiding itself under the product list)


// --------------------------------------------------
// Handlers for data coming in from server
// --------------------------------------------------

// This executes when a merchandise detail record has been received
function MerchDetailProvider_Result(result) {
// The result variable is a recordset that contains just one row
// The detailRecord variable will represent the row of data
var detailRecord = result.getItemAt(0);

// Display detail information in text boxes

_root.DescriptionTextBox.text = detailRecord.MerchDescription;
loadMovie("../images/" + detailRecord.ImageNameSmall, _root.ImageMovie);

// If the ImageNameSmall column contains an image filename, display it

// Now that the information about the merchandise has been placed,
// make the display slide back into view, revealing the information

}

// Stop here, so animation doesn't occur until user selects a product
stop();


MerchProviderCFC.cfc

<!---
Filename: MerchProviderCFC.cfc
Author: Nate Weiss (NMW)
Purpose: Creates a ColdFusion Component that supplies data about products
--->

<cfcomponent hint="Provides data about merchandise records." output="false">


<!--- merchDetailProvider() function --->
<cffunction name="merchDetailProvider" returnType="query" access="remote"
hint="Returns details about a particular item in the Merchandise table."
output="false">



<cfset var merchQuery = "">

<!--- Query the database for merchandise records --->
<cfquery name="merchQuery" datasource=" Mydatabase.mdb" maxrows="1">
SELECT MerchID, MerchName, MerchDescription, ImageNameSmall, MerchPrice
FROM Merchandise
WHERE MerchID = 12
</cfquery>



<!--- Return the query --->
<cfreturn merchQuery>
</cffunction>

</cfcomponent>



MerchDetailProvider.cfm

Same as above example on localhost…



MerchRecordsetProvider.cfm

Same as above example on localhost…