24 May 2007

Convert Lines to Fills - smoothing shapes in Flash

This is a quirk of Flash, which has caught me out a few times. If you're drawing a rounded rectangle with an internal fill colour and a stroke (outline) of 3 pixels, for example, then you get a rather jagged apperance between the fill colour and the stroke.

If you zoom into the shape, all looks fine and smooth, but zooming back to 100% the problem appears again.

To solve this, you must select the stroke (outline) of the shape - double click it to make sure all of it is selected. Then choose Modify > Shape > Convert Lines to Fills.

This solves the problem and your shape now looks smooth.

17 May 2007

Extensible ServiceLoader

As part of the solution to the problem below, I've created a new ServiceLoader class that can be used for any remoting applications. Here's the class:


import mx.remoting.*;
import mx.rpc.*;

class com.utils.ServiceLoader {

private var __servicePath:String;

function ServiceLoader(servicePath:String){
__servicePath = servicePath;
}

private function __openService(remoteName:String):Service {
trace(remoteName);
return new Service(__servicePath, null, remoteName);
}


public function callService(serviceName:String, methodName:String, scope:Object, success:String, error:String, args:Array):Void{
var pc:PendingCall = __openService(serviceName)[methodName].apply(this,args);
pc.responder = new RelayResponder(scope, success, error);
}
}

Here's an example call of this class:

var service:Object = new ServiceLoader("http://localhost:8300/flashservices/gateway/");

service.callService("serviceName", "serviceMethodName", this, "successHandler", "errorHandler" [,optional argument Array]);


So the ServiceLoader class calls whatever service you need and returns the result to handlers in a specified scope ("this" i.e. the calling class, in above the example).

Accessing class function using a string

Here's a piece of dodgy looking code - but it works!?

I've got a class called "ServiceLoader" which contains many service calls, I also have buttons which correspond to these service calls. I've named the buttons as the ServiceLoader function names e.g. "getRecord" button corresponds to the "getRecord" function in my ServiceLoader class.

So I can grab the button name, which is a String and then call a function within the ServiceLoader class using associative array syntax:

var func:String = activeButton._name;
ServiceLoaderInstance[func](arg1,arg2);

I'm not sure how "correct" this is, but it works. Any thoughts?

09 May 2007

Adobe Flash CS3 - 3 minute load!?

I've just downloaded Flash CS3. It promises much, but at 1.2GB, the install seems a little on the large side. Along with Flash comes Adobe Bridge, Device Central (whatever that is), ExtendScript Toolkit (eh?), and the video encoder. I'm sure all of these apps will be quite useful, once I've got to know what they do.

To my annoyance, Flash CS3 seems to have been Adobefied in the same way as Acrobat Reader 8. Every time I try and open a pdf, no matter how big or small, Acrobat Reader grinds to a halt for about 5 minutes or crashes completely.

I have a 3GHz dual core machine with 2GB of RAM and it takes 3 minutes for Flash CS3 to start!

I'll put this down as a trial version quirk and hope the final version isn't as slow. But I'm not holding my breath, after 3 minutes I'd be clinically brain dead!

07 May 2007

Flex Coldfusion Integration - don't follow Adobe!

So... I've had a bit of free time at work to brush up on Flex, specifically Flex and Coldfusion integration.

I've been doing Flash remoting with Coldfusion Flash forms, which were really Flex 1.5. for the last 18 months. I followed the CFC structures as described on www.asfusion.com and ray.camdenfamily.com: store your CFC's in the Application scope and access them with a lightweight proxy CFC that handles the remoting. This structure improves performance, as the proxy CFC is instantiated on each request and it acts as an interface to the bulky CFC's that do all the complicated stuff. From Flex's point of view, this proxy CFC acts just like any other web service on any platform.

So I've been confused by Adobe's instructions for Flex / Coldfusion integration. They suggest you create Actionscript equivalents of your CFC's and essentially map the properties and methods of the CFC into Actionscript. This has the benefit of accessing CFC's as if they were native classes and there'd be no problem with handling data types - essentially extending Flex with Coldfusion.

However, my new job is in Calgary, Canada, where PHP reigns and Coldfusion is a rarity, hardly anyone uses it. So why would I create a Flex app which is so intertwined with Coldfusion? Even if I was in a Coldfusion centric environment, I still wouldn't build this way as I may need to port the Flex application to another Platform. I could quickly convert the CFC's to PHP classes and have no need to change the Flex application at all.

The reason I rant, is that I've been following Flex tutorials which have been confusing and going against what I thought was "right". I think I'll just stick with tips from AS Fusion and Ray Camden from now on!