Adobe ColdFusion 8

Invoking component methods in CFScript

The following example shows how to invoke component methods in CFScript:

<!--- Instantiate once and reuse the instance.--->
<cfscript>
    tellTimeObj=CreateObject("component","tellTime");
    WriteOutput("Server's Local Time: " & tellTimeObj.getLocalTime());
    WriteOutput("<br> Calculated UTC Time: " & tellTimeObj.getUTCTime());
</cfscript>

In the example, the three CFScript statements do the following:

  1. The CreateObject function instantiates the tellTime CFC as tellTimeObj.
  2. The first WriteOutput function displays text followed by the results returned by the getLocalTime method of the tellTimeObj instance.
  3. The second WriteOutput function displays text followed by the results returned by the getUTCTime method of the tellTimeObj instance.

In CFScript, you use the method name in standard function syntax, such as methodName().