Amfphp Remote Service class

Submitted by matthew on March 29, 2010 - 1:38pm

I have told you all that I would post this a while ago so here it is. This is the class I use to dynamically grab data via amfphp programmatically in actionscript 3 without needing to create a remote object mxml node.


package com.mrconnerton.proxy
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.external.ExternalInterface;

import mx.core.Application;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.Operation;
import mx.rpc.remoting.RemoteObject;

[Event(name="result", type="mx.rpc.events.ResultEvent")]
[Event(name="fault", type="mx.rpc.events.FaultEvent")]

public class RemoteService extends EventDispatcher implements IEventDispatcher
{
private var channelSet:ChannelSet = new ChannelSet();
private var channel:AMFChannel;
private var service:RemoteObject = new RemoteObject();
private var operation:Operation;
private var _source:String;
private var _method:String;
private var _faultAt:String;
private var url:String = ExternalInterface.call("window.location.href.toString");
private var gateway:String = "amfphp/gateway.php";

public function RemoteService(source:String, method:String):void {
channel = new AMFChannel("amfphp", url+gateway);
_source = source;
_method = method;

operation = new Operation(service);
channelSet.addChannel(channel);
service.destination = "amfphp";
service.channelSet = channelSet;
service.source = _source;
}
public function send(...args):void {
service.getOperation(_method).addEventListener(ResultEvent.RESULT, resultHandler);
service.getOperation(_method).addEventListener(FaultEvent.FAULT, faultHandler);
var func:Function = service.getOperation(_method).send;
func.apply(service.getOperation(_method), args);
}

public function resultHandler(event:ResultEvent):void {
service.getOperation(_method).removeEventListener(ResultEvent.RESULT, resultHandler);
service.getOperation(_method).removeEventListener(FaultEvent.FAULT, faultHandler);
dispatchEvent(event);
}
public function faultHandler(event:FaultEvent):void {
service.getOperation(_method).removeEventListener(ResultEvent.RESULT, resultHandler);
service.getOperation(_method).removeEventListener(FaultEvent.FAULT, faultHandler);
dispatchEvent(event);
}
}
}

Then anywhere in your flex (or flash) application you want to call an amfphp method you use:


private function loadNode():void {
var rs:RemoteService = new RemoteService('node','load');
rs.addEventListener(ResultEvent.RESULT, onNodeLoad);
rs.addEventListener(ResultEvent.RESULT, function(event:ResultEvent):void {
rs.removeEventListener(ResultEvent.RESULT, arguments.callee);
var node:Object = event.result;
// Do stuff with node
}
rs.addEventListener(FaultEvent.FAULT, function(event:FaultEvent):void {
rs.removeEventListener(FaultEvent.FAULT, arguments.callee);
// AAAAHHHH!!!!!!!!
}
rs.send();
}

Drupal Camp Nashville

Submitted by matthew on March 13, 2010 - 3:57am

Come check out Drupal Camp Nashville tomorrow! Registration is free and so is the beer.

I will be presenting two sessions, one on Drupal & Flex integration and another on Features and Drupal Distribution.

Slides, resources, and videos to come later.

Addon domain for plesk

Submitted by matthew on December 28, 2009 - 4:09pm

I am a avid cPanel user. I love it and all of its features, however the company I work for has servers with Plesk installed. Today I had to launch a micro site with its own domain, but was a sub directory of the parent domain.

Plesk does have the option to create domain aliases but those are basically parked domains with no options beyond that. So, here is what I had to do.

Instead of adding a domain to the parent domain, I had to create a new domain by going to Domains -> Add New Domain.

Next I picked the client to get to the domain configuration.

The key is to select "0 - Domain Forward" as the template for the domain.

On the hosting page it will ask what kind of forwarding do you want to do? Pick "Framed Forwarding" which will redirect the user to parent domain without them knowing it.

On the next screen you can put in the url to the parent domain and subfolder and all is good!

Yay Drupal Camp Chicago

Submitted by matthew on December 15, 2009 - 2:36pm

Got home from Drupal Camp Chicago yesterday and had a great time. Got there on Saturday just as registration was over and mingled with a few old and new friends before I headed to the first session.

Up and Running with Ubercart was a fantastic session. Tim Hill with the Commerce Guys installed a Drupal website using their UberDrupal installation profile and had a nearly full ecommerce Drupal based website up and running within about fifteen minutes. It was great. All you really had to do is add products and a payment processor. They had an example project and image handling all setup ready to go. It was great. I look forward to giving it a run.

Next I headed to Drupal as a Web Service where CM Lubinski showed us how to you the services module to push data to and from a Drupal installation.

Views to the next level by the one and only Larry Garfield was a great session showing off some views kung foo. Also learned about some additional modules to make views even better. I do feel like a views ninja.

After lunch I had planned on attending the panels session, but so did 300 other peopled. I then moved over into Contribute to and build the Drupal community in ways that contribute to and build your success. which was a great discussion with Benjamin Melançon on how to contribute to the Drupal community with time, money, and love.

Next I moved down to Coming soon to a Drupal near you with Larry Garfield again. I had not really spend much time looking at D7 but after that session I have plans to checkout head and get that installed. It was quite an amusing session as Larry had to get through an hour worth of slides in 45 minutes. There is too much to list here but I can't wait to dive in and play with the new features.

The last session I went to was Building an Open Source Business with Drupal which was with George DeMet the founder and CEO of Plantir, one of the platinum sponsors of Drupal Camp Chicago. It was a great session on how he went from just a guy and computer back in 1996 to one of the finest Drupal consultation companies out there today.

After all those session was a short break then I went out with my friend Jamie to an after party where I got to mix and mingle with some great Drupal developers / designers / business people.

My favorite part of the evening was getting to talk with Matt Farina, drupal developer and co-host of Geeks and God. I had a great time meeting him and talking about getting married. It was really cool to see how much he lit up when he talked about how much being married was awesome. Just a neat time.

The next day was the UnConference. I sat in on a few topics here and there and had two sessions of my own on setting up a development and live environments using subversion. I should have some resources from those sessions up here in the next few weeks. I was a little bit bummed that while I was doing my sessions, I missed "Everything in Code" which solved a lot of the issues of having a two databases for development and live environments.

After that I stopped by a few more topics ending with the Interface Module which looks awesome.

Looking forward to the next Drupal camps coming up and DrupalCon of course!

CKeditor and Thickbox with Flex 3 Tutorial

Submitted by matthew on December 2, 2009 - 2:10pm

So I have always hated the built in rich text editor that comes with flex and have always looked for alternatives. With drupal websites I am a fan of FCKeditor but a while back I took some time to try their new CKeditor and found it to be quite amazing.

So, I decided that for now on, I wanted to use it as kind of a pop out text editor for my flex applications using ckeditor and thickbox.

First thing I had to do is include the ckeditor library, functions, and container for the editor in the html file where the flex application lives:


<html>
<head>
<link rel="stylesheet" href="scripts/thickbox/thickbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="scripts/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="scripts/thickbox/thickbox-compressed.js"></script>
<script type="text/javascript" src="scripts/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#save').click(function(){
var data = CKEDITOR.instances.ckeditor.getData();
flexApp.returnEditorData(data);
tb_remove();
});
$('#cancel').click(function(){
flexApp.cancel();
tb_remove();
});

});

function launchEditor(data) {
if(CKEDITOR.instances.ckeditor){
CKEDITOR.instances.ckeditor.destroy();
}
if(data == null) data = "";
CKEDITOR.replace('ckeditor',{ customConfig:'/js/ckeditor_config.js', toolbar:'sitemanager', height:($("#flexApp").height()-250)});
CKEDITOR.instances.ckeditor.setData(data);
tb_show('','TB_inline?height='+($("#flexApp").height()-100)+'&width='+($("#flexApp").width()-100)+'&inlineId=editor;modal=true');
$("#flexApp").blur();
CKEDITOR.instances.ckeditor.focus();
}
</script>
</head>
<body>
<embed width="100%" height="100%" align="middle" type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer"
allowscriptaccess="sameDomain" wmode="opaque" name="flexApp" id="flexApp" src="flexApp.swf"/>
<div id="editor" style="display:none;">
<textarea class="ckeditor" name="ckeditor">Enter text here...</textarea>
<div id="actions"><a id="save" href="#">Save</a> | <a id="cancel" href="#">Cancel</a></div>
</div>
</body>
</html>

The $('#save').click(function(){ will pull the data from the editor and call a method we will create later in the flex application to accept the data back and then it closes the window.

The $('#cancel').click(function(){ will call a flex method cancel and close the window.

The function launchEditor(data){ is the method that the flex application will call to open the editor. It will accept one variable which will return data to the editor to be modified.

Now in the flex application we will create an editor component which will use the ExternalInterface class to communicate with the javascript we just created.


<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import flash.external.*;

private function init():void {
editor.verticalScrollPolicy = "off";
editor.enabled = false;
}

private function launchEditor(event:MouseEvent):void {
ExternalInterface.call("launchEditor", editor.text);
ExternalInterface.addCallback("returnEditorData",returnEditorData);
ExternalInterface.addCallback("cancel",cancel)
}

private function returnEditorData(data:String):void {
ExternalInterface.addCallback("returnEditorData", null);
editor.text = data;
}
private function cancel():void {
ExternalInterface.addCallback("cancel", null);
}

]]>
</mx:Script>
<mx:TextArea id="editor" verticalCenter="0" horizontalCenter="0" width="100%" height="100%"/>
<mx:Button id="button" label="Click Here To Launch Text Editor" horizontalCenter="0" verticalCenter="0" click="launchEditor(event)" />
</mx:Canvas>

Now when a user clicks on the "Launch Editor" button, it will call the javascript launchEditor method and pass the editor.text as its data variable.

private function returnEditorData(data:String):void { is what the javascript calls to put that nice html data back into the textarea we have in component.

And that's pretty much it. I hope you can use this as a stepping stone in your flex applications to make use of a great wysiwyg editor!

What is Drupal?

Drupal - a completely free, open source content management system that many organizations are using today to provide for their needs. Drupal's many features and add-ons allow it to be used for a variety of website needs. Drupal is a good choice for today's organizations of any size because it is free, easy, and incredibly flexible.

Copyright © mrconnerton.com, 2008-2010. All Rights Reserved Drupal theme by Kiwi Themes.