AS3: Smoothing loaded Pictures

There are a lot of blog posts on the topic of smoothing pictures in Flash after loading. The process goes like this:

private function onPicLoaded(e:Event):void 
			var pic:Bitmap = Bitmap(e.currentTarget.content);
			pic.scaleX = pic.scaleY = 0.2;
			pic.smoothing = true;

But few mention that you also have to set:

stage.quality = StageQuality.BEST;

in order to have the pictures smoothed. Preferably you set this value at the very beginning of your application, in your main class. It’s not neccessary to do it everytime you loaded a picture, its a global setting.

If you are loading your pictures from a different domain there seems to be a problem when there is no policy xml file on that server but you can find solution for that on the web.

Making Fonts Ready For Embedding In Flash AS3

This article describes how you can utilize the Adobe Font Development Kit to rename fonts that Flash does not recognizes because of whitespace in the font name.

If you want to embed a font in AS3 you have to use the font name in the [Embed] metadata. Very often the name of the font is not the same like the name the font is represented in programs like Flash. You can find out the real name but just double clicking it. In a windows environment the internal font viewer opens and you can read the internal name at the very top.

The problems start if the name of the font contains whitespaces like this e.g :
“Univers LT 47 CondensedLt”.

Flash seems to have a problem with fontname like this and will throw an error like:

font 'Univers LT 47 CondensedLt' with normal weight and regular style not found

I do not know any other way around that problem but renaming the font internally. You can use commercial products for this but there is a cost free solution by Adobe.

The Font Development Kit provides us with some useful tools around TrueType and OpenType fonts. The tools are command-line tools without any GUI but you will see it’s easy enough! Follow these steps:

  1. Download the FDK from Adobe (you have to read and agree to the Licence Agreement)
  2. Unpack/Install the package to the folder of your choice (e.g. c:\AdobeFDK)
  3. Put the folder into your Windows Invironment Path so the tools are available from anywhere

Setting Up Your Environment For Adoble FDK

1. and 2. are obvious. Here you can find out how to put your FDK folder into the invironment path from windows. Add the following folder to the windows path:
where [yourPath] needs to be substituted by your path on your harddrive (obvious, isn’t it?).

When you are all set open a command line window (Start-Execute: type in:cmd) and change to the directory your wrongly named font lives in. Now it’s time to test if you setup the path correctly. Type : ttx -h and hit enter. The help description of the tool ttx should be shown. If yes, your are ready to go – if not, check the steps above.

Export A XML Dump Of Your Font

Now you can start to export a xml dump of your font to change the internal name. Type: ttx [yourFontName] (e.g: txx ArialRegular.ttf) and hit enter. Your command window should print something like: Dumping ‘ArialRegular.ttf’ to ‘ArialRegular.ttx’. If you look in your directory you will find exactly that file. Open it with your xml editor of choice (not notepad or any other encoding unaware editor) and you see a hugh xml file.

Changing The Internal Name

If you want have a look around in the xml file to get a glimpse of what a font is made of. But at the end you need to find the position where you need to change the name to get it working in Flash. Search for the name your font is named in Photoshop or Flash. Something like: “Arial Regular”. (pay close attention to the space between the words, thats why AS3 cannot use it. Occationally you will find some places where it is already named like “Arial-Regular”, but as long as you can find places where the name has whitespaces in it and you have the feeling (based on the words arround that position) that this section of the xml file deals with the name of your font, change it to another name without spaces (e.g Arial-Regular). Search for ANY occurance. Afterwards save the file.

Saving The XML Back To A Font File

Now you need to bring that change back into your font file. (making a backup copy of your original file is not neccassary since the tool will not overwrite an existing font file but do it if you want). You can build a font with your changed xml settings by typing:

ttx -m ArialRegular.ttx ArialRegular.ttf

The option parameter m tells the tool to merge a given ttx file with a font file. It should say something like: ‘Compiling ‘ArialRegular.ttx’ to ‘ArialRegular.ttf’. Have a look in your folder and you see that there is another *.ttf (or *.otf) file – your newly created Arial-Regular. Doubleclick the font file and you should see the new internal name “Arial-Regular” in your windows font viewer.

Try to embed that font file and everything should work like a charm.

FlashDevelop: Compiling Multiple SWF In One Project

Normally, if you create a new AS3 project in Flashdevelop you got one single file that is marked as ‘always compile’. Thats your entry point for your project. If you compile your project you only get one output.swf. But if you want to build a site with serveral swfs as modules you have two options:

  1. Create a project file for every module – many project files can exist in one folder OR:
  2. Prepare your main classes of your modules for Quickbuild.

Quickbuild is an option in Flashdevelop to not start an entire project built but build the currently opened file. Quickbuild is available under Tools – Flash Tools – Build Current File (CTRL+F8). Since Quickbuild does not use any compiler arguments you need to define them in the file. Put this at the very top of your class:

* @mxmlc -debug -target-player=10.0.0 -o=bin/Test.swf

What you do with that:

  • enable the file to be debugged. You can see traces in the output panel
  • you compile for flash player version 10.0.0
  • you set the output file to Test.swf in the folder ‘bin’ in your projectfolder

You can find any compiler options at Adobes Manual. If you cannot see the traces when compiling a debug swf make sure you have the debug version of Flash Player installed and restart FlashDevelop – it helps.

Concrete5: Problems Importing Database Backup

If you try to import a sql database dump file from any Concrete5 installation to another one you can get some problems. Here is a checklist(will be updated if necessary) what can happen:

  • if you made a dump file from a Concrete5 installation that runs on a unix system and you now want to import it into a windows environment you have to deal with case sensitivity: Unix DOES care if a table name is ‘myTable’ – Windows DOES NOT care. For windows ‘myTable’ and ‘mytable’ are the same. Concrete5 does use upper- and lowercase letters in there database tables. You can setup your SQL Database to deal with names differently. Here is how: deutsch english.
  • the import script (your dumped file) implies that your local database already has Concrete5 tables in it and before it imports any data it tries to delete the tables. If there are no tables to delete sql throws an error like this: mysql error: [1051: Unknown table ‘AreaGroupBlockTypes’] in EXECUTE(“DROP TABLE AreaGroupBlockTypes;”).
    Edit the sql file and replace any accurance of ‘DROP TABLE’ with ‘– DROP TABLE’, save and import again. It should work now.
  • to be continued…

Setting Up The Zend Framework Locally (Windows7)

  • Download the most recent version at the zend framework download page
  • unzip the package to any location you want (e.g. c:\frameworks)
  • if you have xampp installed you already have a version of zend framework available under \xampp\php\PEAR\Zend. Best would be to just delete all the files in there and copy the content of the library folder from your fresh Zend Framework installation into the folder. Also overwrite the zf.bat und zf.php in D:\xampp\php with the new once in the bin folder of your Zend Framework installation. Now you can skip the next two steps
  • find the ‘bin’ folder containing zf.bat and add the path to your path variable in windows
  • edit your php.ini in your PHP installation. (e.g.: c:/xampp/php/) and add the path of the ‘library’ folder of the zend framework to the includepath. (Search the php.ini for includepath until you find something like that: include_path = “.;c:\xampp\php\PEAR” and just add path to the library folder)
  • add the folder of your php installation that includes php.exe to your windows path like you did before with the bin folder of zend framework
  • now open a command line window (execute – ‘cmd’), navigate to a folder where you want your project to reside in and type:
    “zf.bat create projectname” (replace projectname with any name you want)
  • edit the file hosts in (C:/Windows/System32/drivers/etc/). If you cannot see the etc folder in drivers just type in the path, it’s sometimes hidden. If hosts is not editable or saveable start your editor in administrator mode and make sure no other program uses that file. Enter the following: quickstart.local (that defines a host that routes the url quickstart.local to known as localhost). You can chose whatever name you want, e.g. dev.projectname but make sure to reflect the change in the next step.
  • open your httpd.conf file in your apache config folder (e.g. ‘d:/xampp/apache/conf/’) and search for the term virtualhost and enter somewhere below:
    <VirtualHost *:80>
    ServerName quickstart.local
    DocumentRoot D:/4INLOOP/PHP/zend/quickstart/public
    SetEnv APPLICATION_ENV “development”
    <Directory D:/4INLOOP/PHP/zend/quickstart/public>
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
    Servername needs to be the same like in hosts. Document root needs to point to the public folder of your new Zend framework installation.

If you now start your apache you should be up and running. Open your browser and type in quickstart.local.

If this description was too short the manual from Zend is good stuff.