tutorials

I have written many tutorials and this is the place that you will find them. Most of them are in flash, but a few of them are in ColdFusion. Who knows what ind of tutorials I will create in the future?

All of the flash tutorials can be found on my good friends website Graphic Mania who has many such tutorials on many of the topics in Graphic Design. I started writing for the site back in Flash SC 4, and I still do in Flash CS 6, which as been a number of years. Even though of the many changes in flash we try to keep up, with what is popular today. The later tutorials have been on using flash & AIR, and we are working n some gaming features.

Using the Color Picker
How To Create A Flash Login Screen Tutorial
How To Create A Flash Login Screen Tutorial – Part 2
Embedding Fonts for Components in Flash
Checkbox and AS3 in Flash CS4
Making a Guessing Game in Flash CS4
Please refer to:
For a listing of my ColdFusion tutorials
Select like with cfqueryparam
Create Update Delete example

CF Schedule Issues

I am trying to set up a ColdFusion schedule task on Linux, been having problems. Now I am trying to write the log, to see if the task was ran or not. If anybody can help, as my code does not write the output file 🙁

<!—scheduler.cfm—>

<cfset getDate = DateFormat(Now())>
<cfset getTime = TimeFormat(Now())>

<cfschedule action="update" 
			url="http://localhost/schedule/date.cfm" 
			task="CF Schedule Test" 
            operation="HTTPRequest" 
            interval="Daily" 
            startDate="#getDate#"
			startTime = "#getTime#"
			file="scheduletasklog">

<cflog log="scheduletasklog" text="It Ran!" file="/Applications/WebServer/Documents/schedule/output.cfm" >

<!— date.cfm—>


  <cfset tipdate = #CreateODBCDate(now())#>

<cfquery name="GetMembers">
  SELECT *
  FROM email_alerts
</cfquery>


<cfloop query="GetMembers">
  <cfmail To="#GetMembers.email_address#"
    From="johnbarr@hawaii.edu"
    Subject="CF Schedule Test"
    type="HTML">
		
	 <html>
		 <head>
		 </head>
		 <body>
		
	   	 	<cfoutput>
				Hello #GetMembers.name#<p>
				Today's date is <em>#DateFormat(tipdate, "mmmm d, yyyy")#</em><br />
	  		</cfoutput>
	
		 </body>
     </html>
  </cfmail>
</cfloop>

Flex 4 & Remoting

First the ColdFusion component has not changed

<cfcomponent displayName= "testConn">
	<!--- Establish a Flash Remoting Connection --->
	<cffunction name="getTestConn" access="remote" returnType="string">
        <cfreturn "connection to the ColdFusion 9 Server was successful">
   </cffunction>
</cfcomponent>

The Flex code is a little different and strangely I get quotes return here in the text field, but the same code ran in Flash or even Flex 3 returns no quotes.

The Flex Code with using the Flex 4 SDK & Spark

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	<fx:Script>
		<![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.utils.ObjectUtil;

			private function getTestConn_handler( event:ResultEvent):void {
				Result.text = ObjectUtil.toString(event.result);
			}
		]]>
	</fx:Script>

	<fx:Declarations>
		<mx:RemoteObject id="testConn" destination="ColdFusion" source="testConn">
			<mx:method name="getTestConn" result="getTestConn_handler(event)" />
		</mx:RemoteObject>
	</fx:Declarations>

	<mx:Label id="Result" x="127" y="22" width="395" textAlign="left" fontFamily="Verdana" color="#655E5E"/>
	<mx:Button x="10" y="21" label="Test Connection" click="testConn.getTestConn()"  cornerRadius="5" focusColor="#E6EBF0" chromeColor="#F4F6FA" width="109"/>

</s:Application>

So what has changed in remoting in the new Flex SDk & Flash Builder 4? Not much really.

  • New namespaces
  • the script is wrapped in <fx:Script>
  • the mx:RemoteObject is placed in the  <fx:Declarations>
  • afterwards I have a button and a text field which gets the data from the cfc

okay everything is working, but for the life of me I can get rid of the quote:(


Any ideas to this?

Flex 4 & Remoting

First the ColdFusion component has not changed

<cfcomponent displayName= "testConn">
	<!--- Establish a Flash Remoting Connection --->
	<cffunction name="getTestConn" access="remote" returnType="string">
        <cfreturn "connection to the ColdFusion 9 Server was successful">
   </cffunction>
</cfcomponent>

The Flex code is a little different and strangely I get quotes return here in the text field, but the same code ran in Flash or even Flex 3 returns no quotes.

The Flex Code with using the Flex 4 SDK & Spark

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	<fx:Script>
		<![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.utils.ObjectUtil;

			private function getTestConn_handler( event:ResultEvent):void {
				Result.text = ObjectUtil.toString(event.result);
			}
		]]>
	</fx:Script>

	<fx:Declarations>
		<mx:RemoteObject id="testConn" destination="ColdFusion" source="testConn">
			<mx:method name="getTestConn" result="getTestConn_handler(event)" />
		</mx:RemoteObject>
	</fx:Declarations>

	<mx:Label id="Result" x="127" y="22" width="395" textAlign="left" fontFamily="Verdana" color="#655E5E"/>
	<mx:Button x="10" y="21" label="Test Connection" click="testConn.getTestConn()"  cornerRadius="5" focusColor="#E6EBF0" chromeColor="#F4F6FA" width="109"/>

</s:Application>

So what has changed in remoting in the new Flex SDk & Flash Builder 4? Not much really.

  • New namespaces
  • the script is wrapped in <fx:Script>
  • the mx:RemoteObject is placed in the  <fx:Declarations>
  • afterwards I have a button and a text field which gets the data from the cfc

okay everything is working, but for the life of me I can get rid of the quote:(


Any ideas to this?

Redirecting with ColdFusion

Redirect a URL with ColdFusion

ColdFusion can be used to redirect your website to another domain name or URL. The code is very simple, just follow the steps below.

1. First create a new file called index.cfm using notepad or dreamweaver. Make sure you save it as a .cfm (ColdFusion) file.

2. Place the following code in the index.cfm file.

<cflocation url="http://www.example.com">

If you need to redirect to a certain page use the following code

<cflocation  url="http://www.example.com/page.cfm">

Replace example.com with the domain name you wish to redirect to.

3. Upload the index.cfm file to the root of your domain name. The root of your domain is the content location, the directory your domain name’s content is located in. Make sure to replace any existing index.cfm and delete any other default documents such as default.cfm or home.cfm as these will stop the redirect from working.

ColdFusion & XML

<cfxml variable="students">
<school>
        <name>John Barrett</name>
        <school>University of Hawaii</school>
        <department>New Media</department>
</school>
</cfxml>
<cffile action="write"
file="#getDirectoryFromPath(getTemplatePath())#students.xml"
output="#students#">
<!--- dump results--->
<cfdump var="#students#">

This produces the file students.xml in the same directory, with the following results


<?xml version="1.0" encoding="UTF-8"?>
<school>
        <name>John Barrett</name>
        <school>University of Hawaii</school>
        <department>New Media</department>
</school>

Now the next is where I am strgugling, I would like to have a form, that will update this file.

an example form would be


<!--- Simple JavaScript Sample --->
<script language="javascript">
    function checkFields(frm) {
        alert('Dear ' + frm.name.value + ', This validation occurred after the CF validation.');
    }
</script>

<!--- Basic ColdFusion Form --->
<p>All Fields are required!</p>
<cfform action="form_action.cfm" method="post" name="myForm" onSubmit="return checkFields(document.myForm)">

<table width="200" border="1">
  <tr>
    <td>Name:</td>
    <td><cfinput type="text" name="name" size="20" required="true" message="You must enter your name!" /></td>
  </tr>
  <tr>
    <td>School</td>
    <td><cfinput type="text" name="school" size="20" required="true" message="You must enter your school!" /></td>
  </tr>
   <tr>
    <td>Department</td>
    <td><cfinput type="text" name="department" size="20" required="true" message="You must enter your department!" /></td>
  </tr>
</table>

    <cfinput type="submit" name="submit" value="submit" />
</cfform>

Now I would like to take the form fields are update the students.xml file.

First beofre I can update the file with cffile I need to figure out:

* reading the XML data with ColdFusion
* finding the last node
* creating new nodes with the new data

Update

I would really like to thanks @Clarkee21 on twitter for all his help tonight!

Looked on the CF Docs page, and I could not find an example to help complete this.

so using the XmlElemNew function should update the file. So I tried this tonight


<cffile action="read" file="#expandPath('./students.xml')#" variable="xmldoc">
<cfset mydoc = XmlParse(xmldoc)>
<cfdump var="#mydoc#">

This reads the current xml doc students.xml and dumps the results

now to write to a file in ColdFusion you use cffile =”write” and there is a parameter for output, which will write that data there. Now there is no need to re write the whole file, just want to add a new entry in the form


<school>
        <name>new student</name>
        <school>new school</school>
        <department>new dept</department>
</school>

the above is just dumy code, but you get the point.

In the past I have alway used cfquery to write the data to the database, and then create a file to convert the database records to a XML file. The CF Docs had a great example for this.

However, when looking to just simple updating the XML, I can’t seem to find one code example for Help. I alsays asked in CF Talk, and asked on the Adobe Foum, but no luck. Thanks to twitter looks like I will get some Help, thanks to @charlie21, and to Ray Camden!

It is so late here, and I need to get to sleep, but I think that the CF Docs should provide a good example on how to do something as basic as updating the XML like this.

Somebody at work should be a way in php in just a few lines. I love CF, and I always want to do things in CF. I must be missing something here, as it can’t be this difficult!

I would say to adobe that a good example that somebody can onto the docs and find an example to do this would be a good idea.

This is the first example that I have experienced using ColdFusion, where using CF didn’t turn something that was hard in other languages and made it trivial. comes to mind! this tags makes working with the database so easy, as in other languages it is difficult.

testing your cfcs

This post is to explain how to test your cfc to make sure they are working the way that you meant. I am wondering if it is possible to test a cfc directly using cfdump? However, since you don’t run a cfc directly, this may not work.


<cfcomponent>

    <cffunction name="getArtist" access="remote" returntype="query">
        <cfset var qRead = "" />

        <cfquery datasource="cfartgallery" name="qRead">
            SELECT artistid, firstname, lastname, email
            FROM artists
        </cfquery>

        <cfreturn qRead />
    </cffunction>

</cfcomponent>

to test the cfc I create a test file and invoke the cfc and then use cfdump to see the results


  <cfinvoke
     component="ArtistGateway"
     method="getArtists"
     returnVariable="qRead">

     <!--- dump the output--->
     <cfdump  var = "#qRead#">

Happy Coding

Setting up Flash Remoting with AS 3 & ColdFusion

Setting up flash remoting with actionscript 3.0 and ColdFusion
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>

When you run your flash file you should see this in the output window

download project

Move com folder to your ColdFusion localhost host, if you are running the default set up you will need to change the port to 8500. Then run the fla file, you should be fine, with flash & ColdFusion working together!

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.

New Features in ColdFusion 9

Office file interoperability—Dynamically generate office documents for reporting, decision making, and presentations. Read, create, and update spreadsheets using the new CFSPREADSHEET tag. Programmatically generate PDF files from Microsoft PowerPoint and Word files. Dynamically produce presentations in HTML or SWF from PowerPoint presentations directly on the server.

Object-relational mapping—Build database-independent applications using object-relational mapping (ORM) based on the open source Hibernate library. Save time and manage database logic and connectivity without writing any SQL. Use the ORM Application Wizard in ColdFusion Builder to generate ColdFusion components (CFCs) for logic and connectivity without writing a single line of code.

Microsoft Office SharePoint integration—Expose data from Microsoft Office SharePoint web services to a ColdFusion application with the new CFSHAREPOINT tag. Additionally, use the single sign-on capability in SharePoint to display a ColdFusion application as a web part within a SharePoint site without requiring users to reenter their credentials.

Enhanced Adobe Flash Platform integration—Take advantage of faster Flash Remoting to help increase application performance. Use ColdFusion as a Service to speed up RIA development by easily accessing many existing enterprise services via AMF without writing a single line of CFML.

ColdFusion as a Service—Leverage the power of ColdFusion enterprise services via AMF or SOAP without writing a single line of CFML. These services include CFCHART, CFDOCUMENT, CFIMAGE, CFMAIL, CFPDF, and CFPOP. Also make your application more secure by sandboxing these services to prevent access by unknown applications.

Adobe AIR® local/remote database synchronization—Offer users applications with online/offline capability featuring reliable data management. Using SQLLite in the client and ORM on the server, ColdFusion 9 dynamically manages conflict resolution and data synchronization between the client and the server when your application comes back online.

New Ajax controls—Build more compelling and intuitive applications with a broader set of Ajax controls that leverage the new Ext JS 3.0 library via CFML tags and attributes. New controls
include mapping, multimedia player, multifile upload, accordion navigation, progress indicator, confirmations, alerts, buttons, and sliders.

Server Manager—Save time by simultaneously performing administrative tasks across multiple servers from one central console. You can create data sources, schedule tasks, apply hot fixes, clear caches, and compare settings across a cluster of ColdFusion servers.

Built-in support for portlet standards—Expose a host of enterprise applications, including ColdFusion applications, in one integrated portal. ColdFusion 9 allows you to define a ColdFusion component as a portlet. This includes support for Java Portlet Specifications JSR 168 and JSR 286.

Tight integration with ColdFusion Builder—Leverage the power of ColdFusion Builder, a highly customizable, Eclipse based IDE that enables developers to build ColdFusion applications faster than ever before.

PDF link
http://www.adobe.com/products/coldfusion/pdfs/cf9_feature_comparison_matrix_ue.pdf

JRun Settings for Apache 2.2

This should be installed by default, but just in case it is not, you can add it manually.

You can find the httpd,conf file at /private/etc/apache2/httpd.conf

So in case when you install the ColdFusion server under JRun and the JRun settings do not get written in the httpd.conf file, just add this

# JRun Settings
LoadModule jrun_module /Applications/JRun4/lib/wsconfig/1/mod_jrun22.so
<IfModule mod_jrun22.c>
 JRunConfig Verbose false
 JRunConfig Apialloc false
 JRunConfig Ignoresuffixmap false
 JRunConfig Serverstore /Applications/JRun4/lib/wsconfig/1/jrunserver.store
 JRunConfig Bootstrap 127.0.0.1:51020
 #JRunConfig Errorurl url <optionally redirect to this URL on errors>
 #JRunConfig ProxyRetryInterval 600 <number of seconds to wait before trying to reconnect to unreachable clustered server>
 #JRunConfig ConnectTimeout 15 <number of seconds to wait on a socket connect to a jrun server>
 #JRunConfig RecvTimeout 300 <number of seconds to wait on a socket receive to a jrun server>
 #JRunConfig SendTimeout 15 <number of seconds to wait on a socket send to a jrun server>
 AddHandler jrun-handler .jsp .jws .cfm .cfml .cfc .cfr .cfswf
</IfModule>

Mine was written just above the last Module at the end of the file, so copy these JRun settings right above the last entry which is

Include /private/etc/apache2/other/*.conf
<Files ~ ".hbmxml$">
Order allow,deny
Deny from all
</Files>