programming

Flash CS4 Gotchas

I've been banging my head against Flash for the last few days and started trying to document a few things.

Can't import fl.controls

For some reason Adobe didn't include them by default so you'll need to add the path to the project.

  1. Open the File > Publish Settings... menu item
  2. Click the Flash tab
  3. Click the Settings... button
  4. Click the Source Path tab
  5. Click the + button and paste in: $(AppConfig)/Component Source/ActionScript 3.0/User Interface

Can't use a Tween on a scrollRect

The Tween class can only change a simple property and the scrollRect need to be changed and the reassigned before it will update. The solution is to add new property to the class and Tween that instead:

  
public function get scrollX():Number {
  if (this.scrollRect) {
    return this.scrollRect.x;
  }
  return 0;
}   

public function set scrollX(value:Number) {
  var r:Rectangle = this.scrollRect;
  if (r) {
    r.x = value;
    this.scrollRect = r;
  }
}

Then you can use a Tween:

  tween = new Tween(this, "scrollX", Strong.easeOut, scrollX, scrollX + 100, 1, true);

Also, you'll want to keep a reference to the Tween object so that it doesn't get garbage collected half way through the animation.

Can't use named HTML entities

Flash's TextField only supports a small subset of named HTML entities (< > & " '). If you're displaying HTML from users or a CMS you'll find that things like ° slips by so you'll need to convert the named entities to their numeric versions.

Flex stops building the foo.html and foo-debug.html files

I've been trying to get up to speed on Adobe Flex for my CS Capstone project. I should mention, by some surprisingly enlightened decision, Adobe offers a free Flex license to students.

Everything was going great until I it suddenly stopped building the foo.html and foo-debug.html files that launch the foo.swf and foo-debug.swf files. Apparently other people ran into this too. I didn't figure out the proper fix for this but I developed a workaround based on a blog post by one of the Flex developers.

Basically, just rename the index.template.html to ${swf}.template.html and then do a clean rebuild. You should end up with bar.html and foo-test.html and be able to get back to work.

Replacing tabs with spaces in files

I've got a bunch of source code that I'd written with 4-character wide tabs. I needed to replace them with spaces. I'm ashamed to admit how long it took me to figure out.

#!/bin/sh
for i in *.[c,h]
do
    expand -t4 $i > tabfree.txt && mv tabfree.txt "$i"
done

Hopefully by posting this I'll save someone (read: me in six months) some time.

PHP One-liners

I'm starting a collection of one-line PHP programs that I've used on the command line.

This removes trailing white space from a DOS file:

C:\>php -r "foreach (file($argv[1]) as $l) {print rtrim($l).chr(13).chr(10);}" user.module > user.module.trimed

This little gem escapes code for inclusion in HTML. The invocation uses UNIX's cat utility, on Widows you could use type:

$ cat test.php | php -r "print htmlentities(file_get_contents('php://stdin'));"

Running multiple versions of Drupal on Windows

Once you've been developing Drupal modules for any length of time you find that you need to test code on multiple versions of Drupal. The easiest way to do this is have separate Drupal releases running as virtual hosts. In this guide I'll walk though setting up Apache virtual hosts for Drupal 5 and Drupal HEAD. I'm assuming you're running Windows 2000 or greater and that you've already gotten Apache, MySQL and PHP setup and running on your local machine.

Syndicate content