Archive for the 'Actionscript 3.0' Category

Flash – HTML5 Drag and drop integration

After seeing Mario Klingemann’s HTML5 drag and drop demo, I wanted to write a library around it and make it a little more cross-browser.

Register the necessary event listeners to the class and react to events such as dragging a file / element over your swf, dropping data or dropping a file on the swf.

FlashDragDrop.addEventListener(FlashDragDropEvent.DROP_DATA, dropDataHandler);

You don’t need to add any extra javascript to your flash embed, the javascript necessary to add the drag and drop support is injected automatically.

You can detect the drag and drop events in the latest versions of Firefox, Safari and IE. Accessing the content of the dropped files only works in the latest version of Firefox (try dropping an image).

You can check out a demo or download the source files.

Webcam Difference Keying

Some of my students are working on a project where they need a photo-booth-like keying application (take snapshot with somebody out of the picture, then step back in the picture and the background disappears). I’ve been experimenting with pixelbender the last week, and created some classes that do just that.

difference_keying

Check out the example, and play around with the parameters. Please note that it works best with a background without too much detail or similarities with the person in front. Also make sure there’s enough lighting.

You can download the source files and play around with them.

CKEditor running in Flex and AIR

CKEditor is the new version of FCKEditor. Following up on my FCKEditor post, I’ve got CKEditor up and running in both flex and air now.

screenshot

Download the library + demo’s at http://blog.aboutme.be/wp-content/uploads/ckeditor_flex_air/ckeditor_flex_air.zip

Again, some release notes (same as FCKEditor actually :-)):

When you extract the zip file, you will find an swc file, an assets folder and de demos folder. If you want to use CKEditor in your own Flex or AIR projects, add the swc to your library path, and the assets folder to your src folder (just like the demo projects).

When you use the component in a Flex project, you need to ensure you set the wmode property to ‘opaque’. Also, if you run it on your local filesystem with Internet Explorer, you won’t see the component. It works fine if you run it on a webserver.

Using FCKEditor in Flex and AIR

One of the most wanted features in Adobe Flex / AIR is a better Rich Text Editor. There are some great ones available for javascript, so why can’t we have an editor with the same featureset? Well, it is actually possible to incorporate existing javascript editors in your Flex / AIR applications.

You can check out a demo at http://labs.aboutme.be/flex_fckeditor/

You can download my library + demo’s at http://blog.aboutme.be/wp-content/uploads/flex_fckeditor/flex_fck_editor_0.1.zip

When you extract the zip file, you will find an swc file, an assets folder and de demos folder. If you want to use FCKEditor in your own Flex or AIR projects, add the swc to your library path, and the assets folder to your src folder (just like the demo projects).

When you use the component in a Flex project, you need to ensure you set the wmode property to ‘opaque’. Also, if you run it on your local filesystem with Internet Explorer, you won’t see the component. It works fine if you run it on a webserver.

Currently it’s possible to get / set the htmlText, and change the toolbar set. I hope you enjoy this component, if you find any bugs or have feature request, feel free to post them in the comments.

CakeSWXPHP – updated to SWX 2.0 beta 1

The first beta of the new version of SWX was released yesterday. This new version brings AS3 and Flash Player 10 support. I decided to update CakeSWXPHP, to support this new version of SWX. You can download a new version, from my CakeSWXPHP page.

Resizing Scrollbars in Flex

I had to create bigger scrollbars, for a flex project which had to run on touchscreens. Their isn’t a real style or property which enables you to do this, but thanks to programmatic skinning, it is quite easy.

First of all, create a class which extends mx.skins.halo.ScrollTrackSkin. In this class, you override the measuredWidth() and updateDisplayList() functions:

override public function get measuredWidth():Number
{
	return 50;
}
 
override protected function updateDisplayList(w:Number, h:Number):void
{
	super.updateDisplayList(50, h);
}

After that, create a class which extends mx.skins.halo.ScrollThumbSkin. In this class, you have to provide the same methods:

override public function get measuredWidth():Number
{
	return 50;
}
 
override protected function updateDisplayList(w:Number, h:Number):void
{
	super.updateDisplayList(50, h);
}

The last class you have to create, is for the scrollbar arrows. This class extends mx.skins.halo.ScrollArrowSkin. Again, you have to override some methods: measuredWidth, measuredHeight and updateDisplayList:

override public function get measuredWidth():Number
{
	return 50;
}
 
override public function get measuredHeight():Number
{
	return 50;
}
 
override protected function updateDisplayList(w:Number, h:Number):void
{
	super.updateDisplayList(50, 50);
}

The final step, is to link these classes in your css file:

ScrollBar
{
    trackSkin: ClassReference("com.mydomain.BigScrollTrackSkin");
    downArrowDisabledSkin: ClassReference("com.mydomain.BigScrollArrowSkin");
    downArrowDownSkin: ClassReference("com.mydomain.BigScrollArrowSkin");
    downArrowOverSkin: ClassReference("com.mydomain.BigScrollArrowSkin");
    downArrowUpSkin: ClassReference("com.mydomain.BigScrollArrowSkin");
    thumbDownSkin: ClassReference("com.mydomain.BigScrollThumbSkin");
    thumbOverSkin: ClassReference("com.mydomain.BigScrollThumbSkin");
    thumbUpSkin: ClassReference("com.mydomain.BigScrollThumbSkin");
    upArrowDisabledSkin: ClassReference("com.mydomain.BigScrollArrowSkin");
    upArrowDownSkin: ClassReference("com.mydomain.BigScrollArrowSkin");
    upArrowOverSkin: ClassReference("com.mydomain.BigScrollArrowSkin");
    upArrowUpSkin: ClassReference("com.mydomain.BigScrollArrowSkin");
}

Programmatic skinning allows you to do even more, you can completely control the layout, and drawing of the components through code.

Good luck!

Actionscript 3.0 Gradients and Curves code generator

Now and then, I have to use the drawing API to draw a gradient, or a bezier curve. Every time, I have to dig through the help, to check the meaning of the different parameters, and where they belong in the function call. To make this more easy, I created a little code generator for gradients, and for drawing bezier curves with Actionscript 3.0.

Gradients code generator:

Actionscript 3.0 Code generator for gradients

Beziers code generator

Bezier curve code generator (AS3)

Flex Flowcharts

Last saturday I went to the Adobe Usergroup meeting in Gent (Belgium). It featured the Adobe Prerelease tour, Christophe’s presentation about Prana and, last but not least a presentation about lovely charts. Loverly Charts is an application to created flowcharts and diagrams online. This reminded me of a project I’ve been working on now and then the last 3 years. It doesn’t have a title / name yet, but it is a flowcharting application aswell.

You can created flowcharts, which are stored in a database. The flowcharts have metadata, like the perspon who is responsable for that chart, name, description, etc… Each step in a flowchart has metadata aswell. Charts can be linked to eachother, so you can describe a main proces which links to sub-processes aswell.

I’ve put a little demo online at: http://labs.aboutme.be/charts/

Enjoy!

benchmarking cakeswx/amfphp

Cakeswxphp enables you to use the cakphp rapid application framework as your remoting backend. No longer writing complex sqls, escaping query strings,… As some of you have noticed, cake does slow your remoting down a bit, as more classes are loaded to give you this ease-of-use. I did some benchmarks, comparing amfphp and swx with cakeswxphp 1.1 and cakeswxphp 1.2. I ran the echoData service 10 times, and took the average speed of those calls. These are the results:

SWX: 346ms
CakeSWXPHP 1.1: 350ms
CakeSWXPHP 1.2: 369ms
AMFPHP: 57ms
CakeAMFPHP 1.1: 111ms
CakeAMFPHP 1.2: 126ms

As we already know, AMFPHP is fast as hell. The CakePHP version is 2x slower because of the extra classes & functions cakephp executes. The difference between SWX and CakeSWX isn’t that big.

After that, I turned out eaccelerator (PHP caching / accelerator system) and ran the benchmark again:

SWX: 347ms
CakeSWXPHP 1.1: 364ms
CakeSWXPHP 1.2: 362ms
AMFPHP: 50ms
CakeAMFPHP 1.1: 64ms
CakeAMFPHP 1.2: 67ms

Not much difference between the first results without the caching, except for the Cake AMF gateway: it seems like using a php accelerator makes the cakeamfphp almost as fast as the native amfphp!

I’ve included the benchmark scripts:

cakeswxphp SWX benchmark
cakeswxphp AMF benchmark (AS3)

Popforge open source

Hooray! Popforge, an ActionScript 3 code library by André Michelle and Joe Elbert is nog open source! I was especially interested in the audio classes, that enable you to generate audio at runtime in AS3. You can check out the library at the google code page.