Multi-threaded Actionscript

Finally!  It's been a long time coming but the actionscript VM is finally multi-threaded as of FlashPlayer 11.4 and AIR 3.4.  The basics of the "threading" is the use of Workers within the VM.  The main SWF can instantiate any number of workers which run in a separate instance of the VM, thus pushing them to the background.  I just finished watching a couple videos on the subject at gotoAndLearn.com.  I highly recommend checking them out for a basic setup of Workers.  

First, here is some info from the AS3 references on Workers:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Worker.html

Here are the videos setting up a project for this:


Additionally, FlashBuilder 4.7 has been upgarded to handle workers very nicely.  Here is a video demonstrating that:

 

MangoBlog post next/previous links

 

MangoBlog is a really nice system out of the box.  However, I finally came across a need that I couldn't find built-in.  A client wanted to have a next/previous link from each post.  Mango does this already for what I call the "Multiple Post" views such as the default view, category view, search view, etc.  It's a little bit of pagination built in.  However, none of this is there by default on the post.cfm page.  

I knew exactly how to do this, but I couldn't find a "Mango" way to do it.  For example, how do I find out what the blog tablePrefix is and what the datasource is.  I will be installing this blog in a multi-site environment soon with all blogs running from the same admin so I definitely needed to figure this out.  

Here's a basic flow of what I did:  

 

FileZilla Issues

I use FileZilla's FTP Client for work and it works great.  CF Webtools also uses the FileZilla server for some of their FTP servers.  We ran into an issue lately where when attempting to connect to a FileZilla server using a FileZilla client, the connection succeeds but will not list out any directory contents.  The fix, as it turns out, is to force UTF-8 charset for the connection.  

Here's a great post by ColdFusion Muse on the subject and details for the fix.

Farcry 6 webtop security override for richtext editor

I ran into a unique situation where I needed to load the tinyMCE richtext editor outside the webtop in a Farcry 6 site.  I was developing a forum script where users who logged in (but did not have webtop admin permissions) were able to post simple forum messages.  The code for that looked like this:

<ft:form>
    <ft:object objectid="" typename="tfMessage" lfields="title,message" lhiddenFields="" legend="Forum Message" />
   
    <ft:farcryButtonPanel>
        <ft:button value="Save" color="orange" />
        <ft:button value="Cancel" validate="false" />
    </ft:farcryButtonPanel>
</ft:form>

The "message" field was the one in question.  Whenever I was logged into the forum as a user with webtop permissions, the rich text editor loaded up just fine.  However, when using a user that did not have webtop permissions, it failed again and again.  I eventually tracked the code down to a file being called (/webtop/thirdparty/tiny_mce/tiny_mce_gzip.cfm) which loads up gzipped .js files needed for the editor.  Even attempting to call this file triggered webtop security and a redirect to the login page, so rather than loading a script as was expected, it was loading up the login page via an ajax call and the editor errored out, leaving just the textarea. 

My fix is undocumented in farcry and may not be the best fix for the situation but was the only one I could come up with for this.  The webtop's Application.cfc file sets up a request scope and then checks security.  Before checking security it ends up calling the projects _serverSpecificRequestScope.cfm file.  So, here's the fix:

In /webtop/Application.cfc, add these lines to the OnRequestStart method toward the top:

<!--- Param override security to false --->        
<cfset request.fc.overrideWebtopSecurity = false />

Then, change the following line (26 in my file):

<cfif not findNoCase( "login.cfm", cgi.script_name )>

To this:

<cfif not findNoCase( "login.cfm", cgi.script_name ) AND NOT request.fc.overrideWebtopSecurity>

By default this will do nothing.  However, this gives you the ability to override webtop security for certain files as needed.  In _serverSpecificRequestScope.cfm, add the following lines:

<cfif FindNoCase("tiny_mce_gzip.cfm",CGI.script_name)>
    <cfset request.fc.overridewebtopsecurity = true />   
</cfif>

Now you have overridden the security in the webtop for this single file, allowing the richtext editor to be displayed outside the webtop.  I emailed the farcry-dev list asking that this be included in a future version.  Not sure if that will happen or not but I'm hopeful.

Android C2DM HowTo

I am in the process of writing my first Android application and this involves using Google's Cloud to Device Messaging (C2DM) Service.  The basic goal of that service is to send messages from the Google Cloud to a device and have the appropriate application respond to the message, even when not currently running.  This is a newer feature in Android as of version 2.2. Because this is new there are not many tutorials or examples out there so I'm posting what I did to get this working.  This is not necessarily the best way, just what worked for me.

1)  You definitely need to familiarize yourself with the C2DM reference site:  http://code.google.com/android/c2dm/index.html.

2)  You will also need to sign up for access:  http://code.google.com/android/c2dm/signup.html

This was almost instant for me, but this is still in beta as I understand it so there may be a wait when you try it

That's all there is to getting started.  From there on out it's all code.  I have included a downloadable package that I used for my project.  I found reference to C2DM classes that Google wrote but I cannot find where I found them so sorry that I can't reference that blog/site.  Here's that package:

com.google.android.c2dm

You will then need to create a class to extend the C2DMBaseReceiver class from the above downloadable package.   Here's a starting point for that code:

package your.package;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.google.android.c2dm.C2DMBaseReceiver;

public class C2DMReceiver extends C2DMBaseReceiver {
    public C2DMReceiver() {
        super(Model.getInstance().senderEmail);
    }

    @Override
    public void onRegistered(Context context, String registrationId)
            throws java.io.IOException {
        // SEND REGISTRATION TO WEB SERVER
    };

    @Override
    protected void onMessage(Context context, Intent intent) {
        Log.e("YOUR_TAG", "Message: Fantastic!!!");
        // Extract the payload from the message
        Bundle extras = intent.getExtras();
        if (extras != null) {
            // DO SOMETHING WITH THE MESSAGE
        }
    }

    @Override
    public void onError(Context context, String errorId) {
        Log.e("YOUR_TAG", "Error occured!!!");
    }
}

Now, in your application code, you need to use the C2DMessaging class to do the registering and un-registering.  Here's code fro that:

Here is registering with C2DM

C2DMessaging.register(this, "YOUR_SENDER_EMAIL@gmail.com");

Here is un-registering with C2DM

C2DMessaging.unregister(this);

That's all the code needed to get this running.  Finding that out took a while for me.  The last thing you need to do is get your AndroidManifest.xml file set up correctly.  Here's what you need to add to get this working (and this is basically straight out of the C2DM reference site):

Add this inside your <application> node:

<service android:name=".C2DMReceiver" />

<!-- Only C2DM servers can send messages for the app. If permission is not set - any other app can generate it -->
<receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
    <!-- Receive the actual message -->
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="YOUR.PACKAGE.PATH" />
    </intent-filter>
    <!-- Receive the registration id -->
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="YOUR.PACKAGE.PATH" />
    </intent-filter>
</receiver>

Add this outside your <application> node:

<!-- Only this application can receive the messages and registration result --> 
<permission android:name="YOUR.PACKAGE.PATH.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="YOUR.PACKAGE.PATH.permission.C2D_MESSAGE" />
   
<!-- This app has permission to register and receive message -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
   
<!-- Send the registration id to the server -->
<uses-permission android:name="android.permission.INTERNET" />

The "YOUR.PACKAGE.PATH" should be replaced with whatever your package attribute is specified in your manifest node:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="YOUR.PACKAGE.PATH"
      android:versionCode="1"
      android:versionName="1.0.0">

I hope this helps people get started in C2DM faster than I was able to get started.  Overall, I have to applaud Google on the Android framework.  This is my first real taste of it and I'm looking forward to writing more apps in the future.