I decided I'd try an FLA-less project using embedded library assets from swfs, but that proved contrary to my workflow. If I'm going to use the IDE for layout, then I've got a good handful of layers. Not just a graphic or three. I want several things to align, you know visually, so I used a visual layout tool to configure my layout. Smart, huh? But you can't pull in an entire timeline worth of assets and then provide the class and still expect to get the whole thing wired up. Flex compiler's gotta be all one child asset at a time within the class.

Despite reading more than once that you could somehow:

[Embed (src="library.swf", symbol="layout"]
public class layoutClass extends Sprite
{
// rest of class here
}

I never got it to work. I only got the directive to work for class property members, not the class definition itself.

You could use composition to pull an entire layout's worth of assets in. But then you've got this magic asset container property that's different from the local "this" context. No, I wanted all the assets linked to the class in one place, like I was used to with the IDE in the first place.

I decided it was worth it to reparent all the assets out of a temporary holder, and reconstruct the layer stack in the new parent.

I knew the code for this wasn't hard or long, but it isn't exactly obvious:

//Layout is a class that can be populated via
//embed directive or by having a 'skin' swc in your classpath. 

var layout:Sprite = new Layout()

var len = layout.numChildren
for (var i=0; i<len ; i++) {
  //move the child into this
  var c = addChild (layout.getChildAt(0))
  //link the property name of the class to the asset
  this[c.name] = c
}

Merry WhateverDecemberweenNewYear.

PNG sequence to SWF

I needed to stitch a stack of PNG images into a SWF using a server process. There are quite a few tools and methods for doing this interactively, but it gets painful if you want an unattended process.

I found SWFTools (includes PNG2SWF.EXE), which handles the awful, complex bit of ... building a SWF from a bunch of PNGs, but then I needed to figure out how to get it to auto-magically use all the PNGs in a specific folder. Essentially, I found a tool that does the hard part, but I needed to cobble together the actual command it should use. Wince if you want to, but I'm a masochist and I hacked together this batch file (like it's 1988, baby):

@echo OFF
SET LIST=

REM Build a list of PNGs
for /f "delims=" %%a in ('dir /b /a-d %1*.png 2^>NUL') do call :process %%a %1

@echo ON
REM now make a SWF!
CALL png2swf -r 20 -o %2 %LIST%

SET LIST=
goto :eof

:process
REM append the next file to the LIST variable
if not "%LIST%"=="" set LIST=%LIST%
set LIST=%LIST%%~2%~1

example usage -- test.bat c:\path\pngFolder c:\path\resulting.swf

I'm sure this is dead easy in linux (you can get swftools in linux flavors too, including source), and I'll send cookies to whoever posts the first working script in the comments.

Note: I'm not sure why this is, but the resulting SWF can't be imported into Flash CS3 as one would expect. If you were going to do that, you could've imported the initial sequence in the first place.

(see the original Mangled Kerning post)

We decided when we started this blog it wasn't going to be a bunch of whine, whine, whine such-and-such doesn't work. If we couldn't find a workaround of some sort, then we were just polluting the search space with more of the same "anyone else have an answer?" You may have dug through some of that to get here. There's value in seeing you're not the only one out there, but it's so limited we decided to avoid it if at all possible.

So. You've got an autosized textfield. You want to use Anti-alias for readability. But you've noticed strange spacing problems around HTML anchors. You've got a few options. I've come back to edit this post several times after seeing opportunities to achieve the same fix with less effort, but I'm preserving some of the more complex work-arounds because the bug is so quirky, someone might have need to try one of the uglier approaches.

1) After setting the htmlText, access the height property of the field, then it's safe to turn off autoSize which will allow correct kerning behavior:

var temp1 = (field.height)
field.autoSize = TextFieldAutoSize.NONE

You won't have to wait additional frames or anything like that. Just remember to turn autoSize back on before changing the text.

2) Set the antiAliasType property of the TextField to flash.text.AntiAliasType.ADVANCED after the field has already been on the stage for at least two (count 'em: 2) frames. That's frame 3 if you're following along at home and your TextField was present on frame 1. Use the visible property to avoid epileptic seizures.

3) It would appear that only authoring-tool-placed TextFields require the extra 2 frames. Create a TextField from code, and you can set the antiAliasType property of the TextField to flash.text.AntiAliasType.ADVANCED in the next frame. Again, use the visible property to hide the layout jump:

var field = new TextField( 20, 20, 500, 1)
addChild(field)

field.embedFonts = true
field.multiline = true
field.wordWrap = true
field.autoSize = TextFieldAutoSize.LEFT

var styles = new StyleSheet();
styles.setStyle("p", {fontFamily: "HelveticaNeueLT Std Med Cn", fontSize: "18", kerning: false, letterSpacing: 0, color: '#CCCCCC'})
styles.setStyle("a", {textDecoration: 'underline', kerning: false, letterSpacing: 0, color: '#FFFFFF'} );
field.styleSheet = styles

field.htmlText = "<p>This top line is necessary to push the content down because that matters somehow in this simple example of <a href=\"http://nowhere.com\">Quirky</a> text in Flash.</p>"

//NEXT FRAME:
field.antiAliasType = flash.text.AntiAliasType.ADVANCED

4) If you must be a sadist, use a hybrid approach to replace authoring tool-placed TextFields with runtime-created TextFields while preserving position, dimensions, autoSizing, styles, etc. And after you've gone to all the trouble, don't forget to set the antiAliasType to advanced. If you're willing to let the original field handle the autoSizing, you can turn off autoSize on the dynamic field, size it according to the first field, and avoid having to wait a frame to set the antiAliasType as in #2. Just remember that if you need to change the field's contents, you'll have to turn autoSize back on. NOTE: Your mileage may vary, but I found that wordwrap was uneffected by this bug, so even though the kerning sometimes jumps around aggressively, I didn't find any changes in wordwrapping, thus no changes in sizing to worry about ... so far.

Installing PDO_MYSQL on CentOS (the easy way)

When deploying LAMP projects, quite often we find ourselves being given access to a newly installed server with distribution-specific default configurations, which are usually very stripped down. Our Carbon Content Management Toolkit, which runs on top of the Zend Framework, uses the PDO_MYSQL driver for data access, along with a few other modules that are typically present in commercial hosting environments, but not always included in an OS's default PHP build.

Getting PEAR, PECL, and a build environment set up can be a time consuming process if you do it from scratch. Luckily most OSs these days come with easy to use package management systems that take care of downloading, building, and installing the packages you need, and their dependancies.

Check the package management system entry on Wikipedia if you're unsure about which package system your OS uses. Each one works a little bit differently, but the concepts are the same. You're going to need to set up your OS's version of the following packages in order to make your life easy:

php-devel
php-pear
mysql-devel
httpd-devel

The package names will differ a bit for each system. The following example uses the Yum package manager in CentOS, and gets PDO_MYSQL up and running in just a few minutes.

# yum install php-devel php-pear mysql-devel httpd-devel
# pecl install pdo
# PHP_PDO_SHARED=1 pecl install pdo_mysql

Add these lines to php.ini:

extension=pdo.so
extension=pdo_mysql.so

Now restart Apache, and you should see your PDO modules in phpinfo(), Robert's your father's brother.
# apachectl restart

If you need to actually make a custom PHP build, you should have everything you need to do that after installing the devel packages. You still may need to build any dependancies that your custom PHP build requires, but your package system should make that fairly easy.

, ,