Archive for the Actionscript Category

A3Tasks update

Posted in Actionscript, Ant, Java with tags , , , , on January 5, 2012 by andkrup

Finally had some time to work on the A3Tasks!

A3Tasks is a little set of Ant tasks for Flash development, made by me (hence the 3 A’s; Andkrups Ant tasks for Actionscript).

Have a look at the repository at bitbucket ( and tell me what you think.

AS2 History class: The construct function

Posted in Actionscript, Development, oop with tags , , , , , , on July 3, 2011 by andkrup

Here’s a little nugget of information that may or may not come in handy. If javascript is to get the revival that everybody is hoping for (with html5 and ajax), this kind of code could prove useful, especially since we’re touching on some common concepts (mostly prototype manipulation).

Also, if you are being forced to develop something for the flash museum, you might need this snippet of code.

But first, some history lecture…

The problem

Most of the time a flash developer is to develop a larger flash application, he wants to have control of the main timeline. As3 developers have it easy with the possibility of creating a Document class and flex coders extends the Application class all the time.

In flash 8 we typically added scripts in the top-most timeline in_level0 but there where always some problems with this approach, especially in modular applications where you could only cast a loaded swf file as a MovieClip and hope that that instance had had some function references added to it, with execution scope being addressed correctly.

Normal MovieClip symbols from the library could map to external as2 classes fine, but the _level0 timeline was out of reach, even though it behaves just like any other normal MovieClip symbol, when loaded into another swf file.

In as3 this architectural problem was addressed with the advent of the Document class, but you can actually do the same in as2:

The Solution

class Main extends MovieClip{
static var instance:Main;
public static function construct(timeline):Void{
timeline.__proto__ = Main.prototype;
Function(Main).apply(timeline, arguments.slice(1));
instance = (Main)(timeline);

public function Main(){

Invoke the static construct method in _level0 in your 2004-tech flash file, with ‘this’ as the first argument like so:



What this method does, is that it replaces the _level0 hidden property __proto__ with the one from your external as2 class, invokes your external as2 classes constructor and in practicality casts _level0 (with the new prototype inheritance chain) as an instance of your external as2 class.

This means that whenever we need to develop modular flash in yesterdays technology, we can stay comfortably in the OO-zone (especially if we also create and implement some interfaces to establish an api), and use _level0 as an instance of your ‘Document’ class

Very nice.

Compiling external javascript files into flash for javascript injection

Posted in Actionscript, design, Development, Flash, javascript, oop with tags , , , , on July 2, 2011 by andkrup

This page contains detailed information about how you inject javascript into the web page that embeds your flash:

One of the drawbacks of adding javascript code directly into your as3 class files, is that it becomes less transparent where to look for the javascript code. But the solution is simply to add the javascript as an embedded resource, like you would a jpeg or png, using the Embed tag.

See this page for an example of how to embed text files:

Once you begin to think about that, you can create a JavaScript class that may help your workflow:

package dk.andkrup.resource {
import flash.external.ExternalInterface;
import flash.utils.ByteArray;

public class JavaScript extends ByteArray {
private var rValue : *;

public function get returnValue():*{
return rValue;

public static function inject(javascript:JavaScript):Boolean{
javascript.rValue =;
return true;
return false;

private function toXML():XML{
return new XML("<script><![CDATA["+this.toString()+"]]></script>");

Extend this class and add an Embed tag, in order to externalize your javascript in a separate *.js file.

Example embed tag:

[Embed(source="../js/javascript.js", mimeType="application/octet-stream")]
public class MyJavascript extends JavaScript{

(above example implies that you have a javascript called “javascript.js” in the relative location “../js”)

Then it becomes a small one-liner to inject your external javascript subclass with the static inject method like this:

JavaScript.inject(new MyJavascript());

Or, in order to retrieve any javascript return value:

var js:JavaScript = new MyJavascript();
trace("return from javascript: "+js.returnValue);

This way you can keep your javascript separate from your actionscript, possibly making it easier to maintain your project.

Disabling the Warning: 1090: Migration issue

Posted in Actionscript, Bugs & Solutions, Development, Flash with tags , , on May 31, 2011 by andkrup

In actionscript 2, eventhandlers was already defined in the MovieClip class, so whenever you needed to run some code in an eventhandler, say in the onLoad function, you could ‘override’ the default (empty) onLoad function and all was good.

In actionscript 3 Flash CS assumes that you’re struggling with migration issues if the compiler encounters a function that is named similar to the actionscript 2 eventhandlers.

If I decide to listen for the Event.ADDED_TO_STAGE, and create  an eventlistener with the name onLoad, I will get the titular warning.

I don’t really need that warning; I like to give the eventhandler a meaningful name and that’s what I think ‘onLoad’ is.

To disable this warning, you can browse to this file on your Mac:

/Applications/Adobe Flash CS5/en_US/Configuration/ActionScript 3.0/EnabledWarnings.xml

(I would assume that the ‘EnabledWarnings.xml’ file is in a similar location on Windows)

and change the enabled-attribute value from true…

<warning id="1090" enabled="true"  label="kWarning_DepricatedEventHandlerError">EventHandler was not added as a listener.</warning>

to false.

<warning id="1090" enabled="false"  label="kWarning_DepricatedEventHandlerError">EventHandler was not added as a listener.</warning>

Automated Bitmap embedding with custom Ant Task

Posted in Actionscript, Ant, Development, eclipse, Java with tags , , , on January 14, 2011 by andkrup

I just made my own Ant Task:

The tutorial on apache ants homepage was very easy to follow and the work to do is really easy as well – if you can run Ant tasks in eclipse you can debug and run your java code as well.

This particular Task allows a user to specify a folder with image files which, when the task completes, each will be embedded in their own as3 class file.

It’s all very basic and there’s a lot of refinement to be done, for example there is a lot of stuff to add to support font embedding, and swf embedding is not supported at all. But this could help shave off some time embedding a lot of external assets without using the flash IDE.

Debug player options

Posted in Actionscript, Development on August 20, 2010 by andkrup

These options are very useful if you want a lot of information out of your flash debug player

Flex 3.5, AIR swc & ANT tasks

Posted in Actionscript, AIR with tags , , , on June 8, 2010 by andkrup

I am stuck on Flex SDK 3.5 at work.

Today I wanted to create a code library swc file with some AIR-specific classes and I wanted to write a build file.

It seems that there isn’t an acompc-task included in the Flex 3.5 sdk (3.5.0 build 12683), so I was using the exec-task and wrote arg-tags to expand the list of included library-paths.

External-library-path is a nice alternative to library-path if you do not want to redistribute code existing in other swc files, but I got into some problems when I wanted to use -external-library-path, because the syntax apparently has to be a bit different.

This syntax is valid but doesn’t work:

<arg line='-external-library-path "path/to/my.swc"' />

This syntax is also valid, but appears to be similar to setting the attribute append to “true” in the compc ANT-task:

<arg line='-external-library-path+="path/to/my.swc"'/>

If you have tried to substitute the library-path option with external-library-path you might have found that you have to set append=”true” and apparently this is how the command-line version looks like.

Error: could not find source for resource bundle …

Posted in Actionscript, Bugs & Solutions on February 10, 2010 by andkrup

So I was working on a simple VideoPlayer class again and I got this error message out of nowhere.

The initial google search gave the following explanation on the FDT forum:

In short the explanation there is that the project is now depending on some definitions found in the code libraries found in the locale/en_US/ folder., but I didn’t explicitly create this dependency so the culprit is obviously somewhere in the code.

I found that by mistake, I imported the instead of the The definition is distributed in the as3corelib.swc that I used in this project, and including this ErrorEvent created a dependency that I wasn’t aware of.

One of the “symptoms” was also that my finished swc file grew 400% in size by including the locale dependencies, as suggested on the FDT forum.

Code distribution strategies

Posted in Actionscript, AIR, Development, eclipse, Flash Extensions with tags , , , , , , , , , , , , on December 11, 2009 by andkrup

With the 4th version of Adobes Creative Suite (CS4), it is very easy for developers to manage code distribution.

The SWC code component

Using the compc compiler from any Flex SDK, you can create a swf code library file (a compiled zip file, containing your compiled classes in an swf file + an xml file describing the contents of the zip file). This shouldn’t be any news for the experienced flash developer.


Managing and distributing swc files is easier if you use some of the tools also provided by Adobe CS4, but first lets talk about what kinds of issues we have distributing code library files.

Ease of installation

It is much simpler to click once on a mouse button than it is to follow a lengthy set of instructions. Technical people, such as developers are more or less used to follow a step-by-step guide so we might be inclined to issue step-by-step instructions that really only help to scare non-technical people away.

A similar problem is when you want to update.

Ease of everyday usage

Working with AS3-based projects, developers have it easy with Version Systems, and if everybody in the shop knows how to work with the chosen VS, code distribution and updates aren’t really an issue.
Working with designers, externals and other kinds of people might put up some restrictions in that you can’t trust people to know how to work with the VS. This means that you must find another way to distribute your code library.

MXP Flash extension files

Bold designers usually have some experience downloading and installing extensions and Adobe has put a lot of work into the extension architecture, so devising a strategy upon the mxp file seems a good idea.

Distribution Strategy

The main strategy is this:

  1. Create the Extension so it contains all the functionality required for people to use the code library and some easy ways to do it (for instance; a JSFL script that inserts the path to your swc file in the current *.fla file in the flash IDE).
  2. Deliver the Extension online.
  3. Facilitate an easy way for users to get update announcements.

1. Creating the MXP extension

MXP Extension files can be made easily with the Adobe Extension Manager2. You can google tutorials on how to create MXP flash extension files, if you don’t know how.

The important part is the <files /> tag. This is where the meat of your extension is.

My best take on what file locations are good to use atm are the Flash configuration folder which you can refer to by using the ‘$flash’ template-variable:

<file source = "as3codelibrary.swc" destination = "$flash/Libraries" shared="true"/>

This will install your swc file ‘as3codelibrary.swc’ into the end-users Flash config folder: (OSX) /Users/<user>/Library/Application Support/Adobe/Flash CS4/en/Configuration/Libraries/as3codelibrary.swc, (XP) C:\Documents and Settings\<user>\Local Settings\Application Data\Adobe\Flash CS4\en\Configuration\Libraries\as3codelibrary.swc.

The Configuration folder is really a mess and if anyone knows of any guidelines as to how to treat these sub-folders, please share.

Along with the swc file I also put a JSFL script enabling the user to add the swc into the compile-path of the current *.fla file. This is quite simple:

var myDoc = fl.getDocumentDOM();
myDoc.libraryPath = "$(UserConfig)/Libraries;" + myDoc.libraryPath;
fl.trace("library paths: "+myDoc.libraryPath);
(Notice that in JSFL, we can refer to the end-users Configuration folder by the variable $(UserConfig))

This file goes into the end-users Commands folder:

<file source = "jsfl/<jsfl filename>.jsfl" destination = "$flash/Commands/" shared="true"/>

, and will be available in the ‘Commands’ menu in the Flash IDE after it has been restarted.

2. Deliver the MXP extension online and facilitate updates

If you have ever tried to use Badger to distribute Adobe AIR applications and/or the ApplicationUpdater AIR packages, ou know how convenient it is to distribute applications online.

The basic idea is to do something similar. If you are a gamer and know Valves Steam application, you can catch my drift.

Steam is a small client that receives information about available content from the Valve servers and compares that information with already installed content.

Creating a small content distribution system that can monitor the status of installed extensions and notify the user if newer versions have been uploaded online is very similar.

This is possible because the Adobe Extension Manager saves copies of installed mxp files + a copy of the MXI file that was used to create the mxp file in a folder similar to the Configuration folder. AIR allows us to access the filesystem and parse the mxi-file for version data.

Have a look in the “Configuration/Extensions” folder: (Mac OS X) /Users/<user>/Library/Application Support/Adobe/Extension Manager2/Configuration/Extensions

Creating AIR applications with FDT

Posted in Actionscript, AIR, Bugs & Solutions, Development with tags , , on September 25, 2009 by andkrup

How do you create AIR applications in FDT?

By googling ‘fdt air’, you get these 2 fine links:


These posts are very nice introductions, but there is something you might want to check out.

Flex SDK version

If you decide to use the Flex SDK with the included AIR, you should use the descriptor xml file that is included with the SDK version you are using.

I got some “descriptor version does not match runtime version“- and subsequently “application filename must have a non-empty value“- errors, because the descriptor xml file format was changed.

Using the sample descriptor file included with the SDK, you will be certain that the format fits the adl executable.

Icon problems

I also encountered some difficulties with packaging icons. I got the error “error 303: Icon icons/AIRApp_32.png is missing from package”, which, as it turned out, comes out when there is a mismatch between where the icon files will be placed in the package, and the icon arguments in the descriptor file. It would be nice to look into this further.

One solution is to comment out any icon tags in the descriptor file, package and then unzip the resulting *.air file (as it really is only a zip file) in order to find the location of the icons. Then put that location into the icon tags and uncomment them in the descriptor file.