Tag Archives: flash

Connecting to Socket.IO 1.0 from flash

Socket.IO is a great socket communication library that I’ve used many times in recent years. To connect to the server from a flash client I’ve had to rely on a library I found on github called FlashSocket.IO, actually on improved fork of an earlie, now stagnant project.

Socket.IO has recently made it to a 1.0 release, which is long overdue seeing as many people have been using it in production for ages. However this is not a ‘finally stable’ 1.0 release. This is more like a 2.0 release with a complete rewrite of the underlying engine and many API and protocol changes. If you were only using it via the official js client and not trying to inspect the internals at all then you can probably just update without a hitch.

However for my flash client this meant trouble. So, I’ve gone through and updated the flash client to work with 1.0, and added a few other features too, such as ssl compatibility (essential for working reliably with public networks), querystring parameter support (for passing arbitrary parameters from the client to the server to be available at connection time) and making the FlashSocket EventDispatcher robotlegs friendly.

It’s up here, so if you need 1.0 compatibility from flash have a go, and let me know if you have any problems.

Seamlessly looping video files in AS3 with Netstream.appendBytes

Often I find, particularly with exhibit type projects, there is a requirement for some looping video.  Often the loop is required as it’s part of the UI, rather than consumable content.  A designer or animator has made some cool effect and video is simply the best way to deliver this asset.

Now there comes a problem  – in older versions of flash player it was quite easy to just loop a video, but in more recent releases it’s broken and according to adobe this is not important enough to fix.

The only way that I found to get around this was to convert the file to a swf with the video on the timeline. I had some success with this, but the quality always suffered and every time the designers updated the asset I had to reconvert. Someone on the bug report suggested however that there might be way to get the video file to repeat seamlessly by using appendBytes but hadn’t provided a working example. So I just ran into this again and decided to tackle it  once and for all – here’s a class that’ll seamlessly loop an flv (appendBytes only supports flv):

Edit: I recently had cause to use this again in a project so have tidied up the code a little and fixed a bug where I had delays in later loops. Also I’ve added a variation for cases where an animation plays in with one video, then loops with another.

TLFTextField and RTL direction in pure AS3 (no IDE or flex)

So I’ve been struggling all afternoon to get TLFTextfield to display direction = Direction.RTL without any success. The rtl text still flowed left to right. I just got it to work with the help of this post

Basically it’s just this bit:

var myFormat:TextLayoutFormat = new TextLayoutFormat();
var myTextFlow:TextFlow=tf.textFlow;
myTextFlow.hostFormat=myFormat;

…needs to go at the end and it all starts working. urgh.