converting times in ColdFusion

I needed to change the time on some local web pages to reflect the time in Hawaii, but I am using HostmySite, which is based in Delaware, and since Hawaii is 6 hours behind of Delaware I needed to make a change.

to get this working is really simple, just by using some variables, one for the server time and another for the local time. Then just use dateadd function. since I know the server is 6 hours behind Hawaii, I just subtract 6 from the server time.

<cfset servertime = Now()>
<cfset time = Now()>
<cfset time = dateadd("h",-6,time) />

to display the server time you would use

#TimeFormat(servertime,'h:mm tt')#

to display the local time you would use

#TimeFormat(time,'h:mm tt')#

then I just display the results in a table

<table>
	<tr>
		<td>Server  Time</td>
		<td><cfoutput>#TimeFormat(servertime,'h:mm tt')#</cfoutput></td>
	</tr>
	<tr>
		<td>Hawaii Time</td>
		<td><cfoutput>#TimeFormat(time,'h:mm tt')#</cfoutput></td>
	</tr>
</table>

*
You can see this example working on my server

Flash Remoting Query is fixed!

The flash remoting issues that I was having is now fixed! The solution was to realize that there is no record set in AS 3, and it is an arrayCollection, and this is why I think that I was getting the [object] returned when I tried to trace the results.

I am so very thankful to flash-db for posting the picture of the Charles debug tool, otherwise I would have never figured this out. I was able to see the name of the headers from their screen shot, but I have yet to figure out Charles myself

Charles

As you can see I needed the serverInfo.initialData

Here is my solution

//Import the classes

import flash.net.*;



//connect to the gateway

var gateway:NetConnection = new NetConnection();

var responder:Responder=new Responder(onResult,onFault);



// name the default cf test server on this machine

gateway.connect("http://localhost/flashservices/gateway/");



// name of the cfc and the function

gateway.call("com.cfcs.testing.GetResults", responder);



function onResult(responds:Object):void {

		var recordcount:Number = responds.serverInfo.totalCount

		//display the total records in the database(recordcount)

		trace("There are"+" "+recordcount+" "+"Members of the Hawaii Flash User Group:"+"n");

		//loop through the records in the database

    	for(var i:Number = 0; i<recordcount; i++){

			var query = responds.serverInfo.initialData;

			//display the results from the database

			trace(query[i]+"n");

		}

}



function onFault(responds:Object):void {

	//loop over the fault structure

	for (var i:String in responds) {

		trace( i + ":" + responds[i] );

	}

}

Remoting Database Troubles

I have been stuggling with getting remoting working for a database result in AS 3 and ColdFusion. I am hoping that somebody can help me out with this.


import flash.net.*;

var gateway:NetConnection = new NetConnection();

var responder:Responder=new Responder(onResult,onFault);



// name the default cf test server on this machine

gateway.connect("http://localhost/flashservices/gateway/");



// name of the cfc and the function

gateway.call("com.cfcs.names.getnames", responder);



/*without the for loop in onResult (trace window [Object][Object])

with the foor loop nothing is traceed, but no errors

*/

function onResult(responds:Object):void {

	for(var i=0; i<responds; i++){

		trace(responds[i].toString());

	}

}



function onFault(responds:Object):void {

	//loop over the fault structure

	for (var i:String in responds) {

		trace( i + ":" + responds[i] );

	}

}

The cfc


 <cfcomponent>

        <cffunction name="getNames" acces="remote" returntype="query" output="yes">

                <cfquery datasource="johnny_flash" name="allNames">

                    SELECT Names, Comments

                    FROM Titles

                </cfquery>

            <cfreturn allNames>

        </cffunction>

    </cfcomponent>

Setting up Remoting with Flex & ColdFusion

To get Coldfusion and flash to talk to each other is just as easy in Flex as it is in flash. Remember Flex is just the tool, and nothing more. When you compile flex you are just created a swf! To start this out I am just setting up the remoting call, later I will write a full app, which I have been meaning to do, but I have been too busy with school lately. You can check out flexcf Which as so many great examples of using this technology. It is run by Paul who has helped me a great deal in CF in the past! You can check out his blog too.

The mxml file


<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()" layout="absolute" pageTitle="Remoting Example" backgroundColor="White">

    <mx:Script>

        <![CDATA[

            import mx.rpc.events.ResultEvent;

            import mx.utils.ObjectUtil;

            import mx.controls.Alert;



            [Bindable]

            public var cfcResponse:String;



            //this gets called when the application is done being created

            public function initApp():void{

                //this calls the confirmCFC method in remoting.cfc

                cfc_ro.confirmCFC();

            }



            public function loadConfirm(event:ResultEvent):void{

                //this binds the cfcResponse var to the result of the RO call

                cfcResponse = event.result as String;

            }



        ]]>

    </mx:Script>



    <mx:RemoteObject id="cfc_ro" destination="ColdFusion" source="com.flex.remoting" showBusyCursor="true">

        <mx:method name="confirmCFC" result="loadConfirm(event)" fault="Alert.show(ObjectUtil.toString(event))"/>

    </mx:RemoteObject>

    <mx:Label text="{cfcResponse}" width="100%" />



</mx:Application>

the cfc


<cfcomponent output="false">



	<cffunction name="confirmCFC" returntype="any" access="remote">

		<cfreturn "This is a test to see if Flex is conecting to ColdFusion, from the file remoting.cfc">

	</cffunction>



</cfcomponent>

Setting up Flash Remoting with ColdFusion

I would like very much to thank Eric Meyer from curious minds

for helping me figure this out`-` I had started to try to convert a actionscript 2 remoting app to actionscript 3, but got really confused towards the end. I saw a post on his blog, and he was nice enough to work with me over e-mail fixing all my confusion!

Check out his blog, lots of great information.

Setting up flash remoting with actionscript 3.0 and flash CS 3.
Create a fla, call it remoting(or something that makes sense to you).

In the actions, type the following code


import flash.net.*;
var gateway:NetConnection = new NetConnection();

var responder:Responder=new Responder(onResult,onFault);





function onResult(responds:Object):void {

	trace("cfc result"+":"+" "+responds.toString());

}



function onFault(responds:Object):void {

	//loop over the fault structure

	for (var i:String in responds) {

		trace( i + ":" + responds[i] );



	}

}



// name the default cf test server on this machine

gateway.connect("http://localhost/flashservices/gateway/");



// name of the cfc and the function in it that you want to hit in dot notation

gateway.call("com.cfcs.getTest.getTestConn", responder/*this is where any arguments to the remote call go*/);



The cfc lives on my localhost/com/cfcs/gettestConn.cfc

The cfc will look like this


<cfcomponent displayName="getTest">

  <!--- Establish a Flash Remoting Connection --->

  <cffunction name="getTestConn" access="remote" returnType="string" output="true">

    <cfreturn "....connection successful">

   </cffunction>

 </cfcomponent>

This is just the set up, and yep just returns the string from the cfc. Once set up, you can use remoting the way that it is meant to be used`-`

Any question, problems? Let me know I will try to help.

I will posting another example on how to display the results from your cfc, and later how to pull database results into your flash movie as well.

happy coding`-`

Foundation ColdFusion 8 for Flash CS4

Foundation ColdFusion 8 for Flash is the only book on the market that teaches designers and developers alike how to combine these two powerhouse programs to create dynamic Web sites and Rich Internet Applications (RIAs). This book covers the latest version of these two programs. It is a must have for Flash professional who want to extend their skills to cover the complete cycle of Web design.

Continue reading “Foundation ColdFusion 8 for Flash CS4”