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;

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