Tagged with “snippet”…

ActionScript 3 TextField Fix

So I ran into this bug in Flash where I was setting a TextField’s htmlText property and the TextField was cutting off letters and causing strange line wrapping (even though its autoSize property was set to TextFieldAutoSize.LEFT). In order to fix this issue, I used this method Luke Sturgeon had developed:

function setHtmlText($textField:TextField, $text:String):void {
    $textField.autoSize = TextFieldAutoSize.LEFT;
    $textField.htmlText = $text;
    var h:Number = $textField.height;
    $textField.autoSize = TextFieldAutoSize.NONE;
    $textField.height = h + $textField.getTextFormat().leading;
}

It seems to work well and it also prevents the shifting of characters when you have any anchor tags within your HTML.

2 years ago on Monday, November 16th, 2009 at 6:09 PM / Permalink

ActionScript Water Filter

I was messing around in Flash tonight and wrote a simple enterFrame loop that applies a rippling water filter to a MovieClip using Perlin Noise.

var bm:BitmapData = new BitmapData(mc.width, mc.height);
var disp:DisplacementMapFilter = new DisplacementMapFilter(bm, new Point(0, 0), 1, 2, 10, 60);
var pt1:Point = new Point(0, 0);
var pt2:Point = new Point(0, 0);
var perlinOffset:Array = new Array(pt1, pt2);

function onFrame($event:Event):void {
perlinOffset[0].y -= 1;
perlinOffset[1].x -= 0.1;
bm.perlinNoise(20, 10, 1, 99, true, false, 7, false, perlinOffset);
mc.filters = [disp];
}

this.addEventListener(Event.ENTER_FRAME, onFrame);

2 years ago on Tuesday, October 20th, 2009 at 12:20 AM / Permalink

Flash 10 3D: Fixing a Blurred MovieClip

Lately I’ve been dealing more and more with Flash 10’s 3D effects, and a problem I keep running into is MovieClips remaining blurry after a 3D transition.

Today I discovered that resetting the MovieClip’s transformation matrix back to its original state (prior to altering any of its 3D properties) seems to resolve this issue. The ActionScript for this would look something similar to:

// Original Matrix
var myMatrix:Matrix = myMovieClip.transform.matrix;

// Reset MovieClip
myMovieClip.transform.matrix = myMatrix;

2 years ago on Wednesday, September 9th, 2009 at 5:47 PM / Permalink

FTP Image Transport to Rackspace Cloudfiles (fka Mosso) »

Wuori wrote this script for transferring a lot of images (around 700,000) from a server (via FTP), generating a thumbnail and sending both images to the Rackspace Cloud (via ReST API). Good stuff!

2 years ago on Wednesday, July 1st, 2009 at 1:48 PM / Permalink