Screendump my Stage

Often in bug testing phase or just to show something it’s a tideus work to screendump your screen and it get as well a problem if you are dependent by the transparency.

Wrote a small debug class that takes a screen dump of the stage and puts the file on a server (PHP).

So put this PHP on a server somewhere.

$name = date(‘Y-m-d H.i.s’);
$filename = $name.’.png’;
file_put_contents($filename, $png);

$name = date(‘Y-m-d H.i.s’);
$filename = $name.’.png’;
file_put_contents($filename, $jpg);
$name = date(‘Y-m-d H.i.s’);
$filename = $name.’.png’;
file_put_contents($filename, $jpg);

Then you can add this class to you project, required is the adobe core package (http://code.google.com/p/as3corelib/).
Download Screendump.as

To use it first set the URI and stage
Screendump.stage = this.stage;
Screendump.URI = “http://localhost:8888/screendump/dump.php”;

After that whenever you need to take a dump, run

By |November 18th, 2009|Flash|0 Comments|

Runtime Dynamic Fonts for CS4 (fp9), next-gen

Runtime Fonts for Flash is a wonderful way when building apps, even better if you are as me and creating international apps for a lot of countries, you have the language supports and the problem with characters in fonts when staring to look at Greek, Japanese, Korea, Chinese and so on. I have a old Runtime font for CS3 that works pretty well. But when starting to use CS4 I wanted to improve the loading and sharing.

So the idea was to use Flex to compile Font SWF files, a big problem when I use Flash CS4 (fp9) and Flex 3. Flex will not recognize my font SWF file, it will also not recognize my local fonts to embed bold/italic font sets. Using an exported CS3 (fp9) file it works just fine.
Note; fp9 = Flash Player 9.

So lets look of how to do this.
First we need to create our font file.
1.) Create an Flex ActionScript project (I use framework 3.2)
2.) The Class name will be something that we will get later so I renamed my as file to FontHolder.as
3.) Remove the constructor and add the embed tags, example below. Note the unicodeRange tag, these are used to select characters to be embedded, remove to embed the entire font.
package {
import flash.display.Sprite;

public class FontHolder extends Sprite
[Embed(systemFont='Verdana', fontFamily='Verdana', mimeType='application/x-font', unicodeRange='U+0061-U+0074')]
public static const verdana_regular:Class;

[Embed(systemFont='Verdana', fontFamily='Verdana', mimeType='application/x-font', fontWeight='bold', unicodeRange='U+0061-U+0074')]
public static const verdana_bold:Class;
4.) Now you have your font SWF file to use for the project.

So with your font file it’s time to use it in the project. In this example I use my Flex 3 as CS3 development tool., this is because I create Flash Player 9 project. You can of course use only Flash IDE or any other […]

By |February 13th, 2009|Flash, Flex|4 Comments|

Encode to FLV

This is a quick help for how to Encode/Convert movies to the Flash FLV format. There are a couple of general encoding features that could be good to know. The key is to find a good balance of frame rate, data rate and keyframe.

When working with digitally compressed video in a format such as Flash Video, the higher the frame rate, the larger the file size. To reduce the file size, you must lower either the frame rate or the data rate If you lower the data rate and leave the frame rate unchanged, the image quality is reduced. If you lower the frame rate and leave the data rate unchanged, the video motion may look less smooth than desired. Something to remember here as well is that you can never gain quality when encoding, so if you have a bad video to start with it will not get any more pleasant to look at just because you boost the data rate.

For short;
Frame rate (fps); The less, the more jumpy.
Data rate (bitrate); The less, the more pixels/blur.
Keyframe; The less, smaller file size.

Since Flash Player 9,0,115,0 there is now the possibility to convert HD quality, so i brief version list of the codecs;
Flash 6-7; Sorenson Video
Flash 8-9; On2
Flash 9-10; On2 (new F4V open format since 9,0,115,0)

There is a really good convert guide to get some help on the export settings;


How to work out the best video compression for me?
This is the hard bit, for short I would recommend these steps.
1.) Figure out a compression that you guess would be the perfect one (get help from calculator).
2.) Setup 4 more compressions, 2 that has higher quality than your (1.) setting and 2 that are below.
3.) Line up all the videos and find the video with the lowest quality settings but that you find is still good. Now from this go back to step 2.
4.) After a couple of rounds this way you should have found a compression for your video.

Remember that all videos are different, so there is no magic setting that will work on all your videos. Also when choosing the “best” video you need to keep track on the file size and what the target is going to be.

By |February 3rd, 2009|Flash|2 Comments|

Cairngorm and Flash

When developing Flash Applications I like to use the Cairngorm micro-architecture as I do in Flex. Without all the nice Flex Framework classes it takes a little more work. Iteration Two did a Cairngorm Flash 0.95 package but that seems to have fallen of the web.
So I took the Flex Open-Source 2.1 Cairngorm classes and removed everything until it started to work.

You can download the Cairngorm to Flash code here.

To think about is that;
- Delegates needs to handle the creation and sending of external services
- Bindable does not exist so instead dispatch when data is updated
There are probably a lot of more things here.

By |October 22nd, 2008|Flash|0 Comments|

Flex 3 as CS3 development tool

I’ve played around a little with Flex 3 Builder. I love the FDT plugin to Eclipse. But I think it’s a little to expensive and for having a use for it I need the enterprise to get debugger functionality.

So I started to search and to play around with my Flex 3 Builder, why can’t I use this??? Well, as it looks like it’s actually possible.

I created a little video tutorial how to set it up. This is my first video tutorial so sorry if it’s a little strange. If anyone got some good tips of how to create video tutorials please let me know because this was harder than I thought. The files are very big so will try to record them all over.

By |July 24th, 2008|Flash, Flex|14 Comments|

Flash 9.0.115 update crash XMLSocket; Socket Security

When Flash 9 update came all XMLSockets stopped working. This is for the sandbox security update for XMLSocket and ONLY XMLSocket. Took me a while to understand the problem and how to solve it.

XMLSocket goes and checks the sandbox security (crossdomain.xml) as all other security related flash things.

XMLSocket wants to check port 843 (default) for a security crossdomain file. This is NOT same file as the crossdomain that is on the web server port 80.

After long searching and reading it’s really 2 things you need to do.
1.) The server must feed client with a special XMLSocket crossdomain file. Download the zip from http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html and read the article, could also be good to read http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html so you know what is going on.
I don’t know so much about servers so on my ubuntu machine i just typed in the terminal.
./flashpolicyd.pl –file=../policyfile.xml –port=843

2.) Flash Client; make sure to run loadPolicyFile(“xmlsocket://mysite.com:843″) or change port number to what you have in #1. When it’s loaded it should all work.
It’s simple as that,,,

Why most people always write lite, I know this but not, This is how you doing it…. Flash Blogs, shape up. =)

By |May 23rd, 2008|Flash, Life|0 Comments|

Developer kit 2.0.8

Released an update to my “Flash Developer Kit” today.
My devkit basically contains eclipse with the wonderful FDT Professional, some Java installs, Perl, Flex compiler files.

Because I have 8 developers to handle I’ve made some rules on what software to use, code rules, architecture and so on. After a lot of hard work it finally pays of. We can now easily get into a projects SVN (using tortoise) and instantly know where to start looking for code when something needs to be done.

I have as well setup a big SVN library with our whole framework, so when starting a new project an ANT script is building up the architecture with files and everything we need to get started fast.

As a general working architecture for the code we are following Adobes Cairngorm (some good docs). Was created for Flex applications, but with some refactorying I got it to work very nice with AS3 projects and is now porting the major functionality to AS2. This makes us be able to work with the same architecture in all projects and does not have to care if it’s Flash 6 or 9 projects.

By |March 26th, 2008|Life|0 Comments|

Guitar Hero “in” Flash

I was writing a new Audio Sync Engine for AS3. The idea is that our Sound Manager is working in Sound Forge, by setting markers he can export an xml file with markers data and positions. I wrote the plug-in in c++ by mashing up some existing plugs.

Then the Flash developers can use the Sync Engine to connect markers to changes for example lip sync, character moods and so much more.

When drinking some beer with the colleges we decided to make our own Guitar Hero game.

By connecting the XBOX 360 Guitar Hero control I could with JavaScript find the control, its movement in X,Y (up and sideways). The only thing that I couldn’t get hold of was the Z (pin to pitch audio).
After getting the JavaScript API to work it is easy to push the data to flash. By ExternalInterface its easier to handle JavaScript handling when not needed to put all handling in root.

By |February 14th, 2008|Flash|0 Comments|

Wii game in Flash

My company had a recruitment fair in Finland. So for dragging people to the “booth” we created a Flash game for the Wii.

HiQ core business is consulting with advanced developers (flash/flex/c++/java and so on).

We created the game “Monkey goes to Work”. A quick game based from the idea “Wario Ware – Smooth Moves”.

By using the WiFi-USB adapter on a laptop and a simple web server I could easily use the Wii Opera browser to get access to our own application.
Some problem with the connection because Wii console needs internet connection to be able to find the computer. It works so long you don’t try to test the connection again, could help to restart the Wii console a couple of times.

Wii Opera supports Flash Player 7. One big problem could we the performance, just having some moving animations and transparency making the application slow.

To control the Flash it’s possible to use remote 1 as a ordinary mouse. But to really get something out of it I used JavaScript to connect to the browser API, possible to get all 4 remotes.
I extracted control 2 and push changes into flash player. Some things for example that I could control is X,Y,Z (distance), Roll (rotating remote), Connection status.
Couldn’t get the gyro to work, probably because all the browser movement is based on the IR. So moving remote outside screen will loose updated. But the buttons is going through wiresless.
Possible to get hold of all buttons on the remote and on the nunchuck. But the nunchuck joystick doesn’t respond.

By |February 12th, 2008|Flash|0 Comments|

Runtime Dynamic fonts Flash CS3

All the examples showing runtime dynamic fonts for flash cs3 includes that you export swf file with a class that contains embedded font [Embed ??my font??].

This doesn’t really works for me because I need specified characters for a lot of different countrys. Usually when developing a flash application I have to handle between 15-50 countrys.

So I made my own little solution, made one of these for flash 6 for a couple of years ago and the trick still works. It basiclly works by loading shared runtime librarys and then embedded fonts will be shared cross the application when using a lot of swf files.

Making it a static class it’s easy to use.
CSS.loadStyleName = “default”;CSS.loadStylePath = “css/”;CSS.addEventListener(IOErrorEvent.IO_ERROR, this.onError);CSS.addEventListener(Event.COMPLETE, this.onComplete);CSS.initialize( this );
And then to use it on textfields.
txtField.styleSheet = CSS.styleSheet;txtField.embedFonts = true;txtField.htmlText = “&lt;span class=’subTest’&gt;Embed Arial&lt;/span&gt;”;txtField.rotation = 5;

txtField2.styleSheet = CSS.styleSheet;txtField2.embedFonts = true;txtField2.htmlText = “&lt;span class=’subTest’&gt;Try embed Arial Black&lt;/span&gt;”;txtField2.rotation = -5;
To make this work.

1.1) Create your shared library file (example: default_lib.fla)

1.2) Create MovieClip on stage and export it for runtime.

1.3) In the MovieClip create a textfield for each font you need, embedd all the characters needed.

2.1) Create your shared library holder file (example: default.fla)

2.2) On the stage add the runtime MovieClip and give it instance name mcFont

3.1) Create your css file (example: default.css)

3.2) Add the styles that your need

4.1) In the Application file add the following load code (look at example in top)

You can download example files here: runtimefonts_as3

By |January 28th, 2008|Flash|11 Comments|