Unix & Apache commands

Apache Commands

Re-Start Apache -sudo apachectl restart
Start - sudo  apachectl -k start
Stop Apache- sudo  apachectl -k stop
Changing Files Names
change .htm files to .html-
for file in *.htm ; do mv $file `echo $file | sed 's/(.*.)htm/1html/'` ; done

change .html files to .htm- 
for file in *.html ; do mv $file `echo $file | sed 's/(.*.)html/1htm/'` ; done
change .html files to .shtml- 
for file in *.html ; do mv $file `echo $file | sed 's/(.*.)html/1shtml/'` ; done
change .html files to cfm- 
for file in *.html ; do mv $file `echo $file | sed 's/(.*.)html/1cfm/'` ; done

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

Getting Database Results into Flex

So I had a fight with Flex tonight, and I won! Well kind of I did let Flex tell me what to name my method, and then we played nice with ColdFusion. The first part is my strange mistake with Flex & ColdFusion getting my database results into a flex datagrid. Afterward I changed the method name to not be plural, and I was able to bind my query into a flex datagrid. I am happy that I got it woring in the end!

I am using ColdFusion 9, with the database that ships with ColdFusion 9.

first make sure you set up ColdFuson with Remoting in you Flex project

First I build the component


<cfcomponent>

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

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

        <cfreturn qRead />
    </cffunction>

</cfcomponent>

I usually like to test to see if the ColdFusion component is working properly


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

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

The cfdump gives the data results expected from the database

Now the Flex part


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">

    <mx:Script>
        <![CDATA[

            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection;

            [Bindable]
            private var acArtists:ArrayCollection;

            private function initApp() :void {
                ArtistGateway_RO.getArtist();
            }

            private function getArtistsRO_Handler(event:ResultEvent):void {
                acArtists = ArrayCollection(event.result);
            }
        ]]>
    </mx:Script>

    <mx:RemoteObject id="ArtistGateway_RO" destination = "ColdFusion" source ="com.cfcs.ArtistGateway">
        <mx:method name="getArtists" result = "getArtistsRO_Handler(event)" />
    </mx:RemoteObject>

    <mx:DataGrid dataProvider = "{acArtists}" right="10" left="10" top="10" bottom="10">
    </mx:DataGrid>

</mx:Application>

Flash player gives me the error

Now I have checked ant the ArtistGateWay.cfc is located in my webroot http://localhost/com/cfcs/ArtistgateWay.cfc and I think that flex looks from the webroot, in my case localhost, so I think that I have the settings right as “com.cfcs.ArtistsGateWay” the strange part is that it is looking for a method “getArtisit” but the method is getArtists

You can download source here

UPDATED– CODE IS FIXED

This is very strange, I changed the method name in the componet to be getArtist, along with the methos name in mx:method and now everything is working!

I did make one extra change to display a friendly error message using the Alerts in Flex

This is done by adding the fault event

First import the necessary classes


import mx.rpc.events.FaultEvent;
import mx.controls.Alert;

In the block add


private function result(event:ResultEvent):void {
    Alert.show(event.toString());
}

private function fault(event:FaultEvent):void {
    Alert.show("Error while calling cfc: nn" + event.fault.message);
}

You will notice I have 2 line breaks (nn) in the Alert.show to give a little spacing, which I find this easier to read!

finally to use the alert add the fault event in , so that the mx:method looks like this


<mx:method name="getArtist" result = "getArtistsRO_Handler(event)" fault="fault(event)" />

Okay now lets go over the correct code

The Flex application


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">

    <mx:Script>
        <![CDATA[

            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection;
            import mx.rpc.events.FaultEvent;
            import mx.controls.Alert;

            [Bindable]
            private var acArtists:ArrayCollection;

            private function initApp() :void {
                ArtistGateway_RO.getArtist();
            }

            private function result(event:ResultEvent):void {
                  Alert.show(event.toString());
            }

            private function fault(event:FaultEvent):void {
                  Alert.show("Error while calling cfc: nn" + event.fault.message);
            }

            private function getArtistsRO_Handler(event:ResultEvent):void {
                acArtists = ArrayCollection(event.result);
            }
        ]]>
    </mx:Script>

    <mx:RemoteObject id="ArtistGateway_RO" destination = "ColdFusion" source ="QueryToDataGrid-debug.cfcs.ArtistGateway">
        <mx:method name="getArtist" result = "getArtistsRO_Handler(event)" fault="fault(event)" />
    </mx:RemoteObject>

    <mx:DataGrid dataProvider = "{acArtists}" right="10" left="10" top="10" bottom="10">
    </mx:DataGrid>

</mx:Application>

The ColdFusion componet


<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>

I have no idea why Flex would not let me use getArtists and would only work using getArtist, maybe it is a caching issue, or just flex does not like plural methods!

Where is the finally correct code if you are interested in using it

The final Flex datagrid

One final update

Flex does not have an issue with plural methods, it was a silly typo of mine!
I would like to thank Paul Hastings from the  CF -Talk mailing list for correcting my problem!
He pointed out, “your error is flex side, your init method is trying to call getArtist() which  doesn’t exist on that service.”

Now everything makes sense, thanks Paul!

I was able to figure this out, and I even figured out how to use the Alerts for an error message, so all in all a good night with Flex & ColdFusion:)

java Vs. AS 3

java


package abc ;

public class C1 extends c2 {
    private int v1;
    public c1() {
        this.v1 = 5;
    }

    int method(int 1) {
        return v1;
    }
}

Actionscript 3.0


package abc{
    public class c1 extends c2 {

        private var v1:int;
        public function c1() {
            this.v1 = 5;
        }
        function method(v1:int):int {
            return v1;
        }
    }
}

In a java application, the main class has to have a main method,
public static void main(String{} args) to start the program.


public class Test {
    public static void main(String[] args) {
        //starting point
    }
}

In a Actionscript 3.0 application, the main class starts the program from its non-arg consructor.

Moreover, the class must inherit MovieClip or Sprite from the flash.display package, otherwise, compile error will occur


package {
    import flash.display.*;
    public class Example extends MovieClip {
        public function Example() {
            //the starting point of the program
        }
        public function Example(args:int) {
        }
    }
}

Remoting with Flex 3

Coldfusion component


<cfcomponent>
<cffunction name="GetHello" output="false" access="remote" returntype="string">
    <cfreturn "Hello World">
    </cffunction>
</cfcomponent>

Flex


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
        <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.utils.ObjectUtil;

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

    <mx:RemoteObject id="helloWorld" destination="ColdFusion" source="HelloWorld">
        <mx:method name="GetHello" result="GetHello_handler(event)" />
    </mx:RemoteObject>

    <mx:Label id="Result" x="59" y="58" width="87"/>
    <mx:Button x="154" y="56" label=" Get Hello" click="helloWorld.GetHello()" />
</mx:Application>

my flash drawing

Last night I was working on my presentation for the Hawaii Flash User Group, and I made a really cool drawing using the drawing API. This drawing is done complete in code!

I hope that you like it, and if you are in Honolulu, please come to the meeting to see how this was done!
[kml_flashembed publishmethod=”static” fversion=”9.0.0″ movie=”http://blog.hawaiiflash.org/wp-content/uploads/2010/03/building.swf” width=”400″ height=”300″ targetclass=”flashmovie”]

Get Adobe Flash player

[/kml_flashembed]

DataGrid Example

I love using FDT now, but in doing so I am also trying to use AS 3, and not use the Flash IDE. Today after going through just hell trying to get web services working, which I can’t get to, I decided to try something else.

I am trying to make a very simple datagride example, now in the Flahs IDE I drag the dataGrid component in the library, and add the actionscript, and everything is cool. However, FDT does not have a library like the Flash IDE and therefore I am trying to get it working just in FDT. I am wondering if it is possible?


package {
    import flash.display.MovieClip;
    import fl.controls.DataGrid;
    import fl.data.DataProvider;

    public class DG extends MovieClip {

        //set variables
        var myDataProvider:DataProvider = new DataProvider();
        var myDataGrid:DataGrid = new DataGrid();

        public function DG():void {
            
            myDataProvider.addItem({ID:"01", Name:"Johnny", Email:"johnbarr@hawaii.edu", Web:"hfug.net"});
            myDataProvider.addItem({ID:"02", Name:"Snoopy", Email:"snoopy@snoopy.com", Web:"snoopy.com"});
            myDataProvider.addItem({ID:"03", Name:"Bugs Bunny", Email:"bugs@bunny.com", Web:"bugsbunny.com"});

            myDataGrid.addColumn("ID");
            myDataGrid.addColumn("Name");
            myDataGrid.addColumn("Email");
            myDataGrid.addColumn("Web");
            myDataGrid.dataProvider = myDataProvider;
            myDataGrid.width = 530;
            myDataGrid.move(10, 10);
            addChild(myDataGrid);
        }
    }
}



Favorite Actionscript 3.0 Editor

So I started a Poll on my Twitter account over the last 2 days. I was curious on which editor did flash developers perfer to use. I did not promote any editor, or tell people how to vote in any way, below is what people voted on.

(1) FDT – Clearly the choice of Flash Developers!
(2) Flash Develop (windows only)
(3) Flash Builder
(4) Other (Text Mate, and Note Pad) I don’t understand this one, maybe so can explain to me?
(5) The Flash IDE – okay nobody likes to code in the Flash IDE, so this dude is last!

Take the vote below on TweetPoll, and voice your opinion!

web services in Flash

So I am trying to figure out how to use webservices in Flash with AS 3. I important the following swc files into the class path in Flash

rpc.swc
frameworks.swc

At first I tried to use the Flex 4.0 SDK, but I got a strange error, which I figure out that I needed to add the textLayout.swc, but instead I am using the Flaex 3.4 SDK, and I turns out that I don’t need the textlayout.swc.

I finally got it to compile, but it does not load, The project can be viewed here
http://hawaiiflash.net/getCountries.html

I think that I might have to stick with remoting! However, i am trying to learn new ways of working with data in Flash

Here is the code ( anything wrong here? I have checked the web service it is working)

import mx.rpc.soap.*;
import mx.core.*;
import mx.rpc.events.*;
import fl.data.DataProvider;

var myWebService = new WebService();

myWebService.addEventListener("load",loadDone);
myWebService.load("http://www.webservicex.net/country.asmx?wdsl");

var myOperation:Operation;

function loadDone (evt:LoadEvent){
    myOperation = Operation(myWebService.getOperation("GetCountries"));
    myOperation.addEventListener("fault",wsError);
    myOperation.addEventListener("result",wsResult);
    myOperation.send();
}

function wsError(evt:FaultEvent){
    trace(evt.fault);
}

function wsResult(evt:ResultEvent){
    var xml:XML = XML(evt.result);
    var dp:DataProvider = new DataProvider(xml);
    MyDG.dataProvider  = dp;
    trace(xml);
}





Big Island Adobe User Group

In case you are on the Big Island there is a new group that has just formed there.

The group is ran by Dan Hoskins The primary focus of the group is for photographers and  designers on the big island.

Looks like an exciting new addition to the Adobe groups family, and is in Hawaii! Seeing from there homepage, there meetings attract a large crowed,

and has a photography focus, and had a meeting on lightroom.

Besides photography, the group also has meetings on photoshop and illustrator as well,

besides other design tools!

Big Island Adobe User Group, a group worth checking out!