Macromedia Components & Object.prototype Don’t Get Along

In most of my flash projects I have a prototype file I include into the project. It contains additions to core objects such as Object, MovieClip, etc. Well, today I found out that some Macromedia components (ComboBox was the one I was having trouble with) don’t like additional methods to be defined on certain classes (Object was the one I found that ComboBox was having issues with); they fail to continue to work with additional methods defined.

However, there is a workaround: ASSetPropFlags. Simply hide all additional methods with this line of code: [code lang=”actionscript”]ASSetPropFlags(Object.prototype, null, 1);[/code]

I can’t wait until AS3 can be used all the time.

Continue Reading

Flash & Fonts

I’ve written about the pains of fonts in flash before; and it something that still plauges my work today. However, since that post new tools have been created, new workflows introduced, and with that some new findings.

Fonts With SWFMILL

SWFMILL is an awesome tool that may allow you to leave the Flash IDE untouched for some projects. However, embedding fonts seems to be scarcely documented (I had trouble getting the methods documented working). Here are the two links I’ve found that document embedding fonts with swmill:

Adding fonts to your SWF with FAMES Using SWFMILL

I wasn’t able to get embedded fonts working using the information above, so here is my method. This is what my swfmill xml looks like.

FontFile.ttf must be referenced relative to the location of the swfml file, and must be a TrueType font for swfmill to read it successfully. If you want to use a non-TrueType font convert it to a TrueType font with a tool such as FontForge (works great and its free, but has a horrific UI).Now if you create a NavButton class that looks something like this:

[code lang=”actionscript”] class NavButton extends MovieClip { private var oTitle:TextField;

function NavButton() { super();

oTitle.selectable = false; oTitle.multiline = false; oTitle.wordWrap = false; oTitle.textColor = 0xFFFFFF; oTitle.autoSize = true; oTitle.text = “This is a title”; } } [/code]

And attach the NavButton to the stage using attachMovie() you should see the text come up. Note: you don’t need to set oTitle.embedFonts = true; to make this work correctly! Actually, dont use embedFonts at all!

You may have noticed the properties that I had to set on oTitle, this will be different for every situation. It seems that swfmill sets a bunch of default properties when creating a textfield. As a reference, here is the output from dumpObject(oTitle) (dumpObject() is a method from my debug class):

[code] styleSheet:undefined mouseWheelEnabled:true condenseWhite:false restrict:null textHeight:48 textWidth:54 bottomScroll:1 length:12 selectable:true multiline:true password:false wordWrap:true background:false border:false html:false embedFonts:true maxChars:null maxhscroll:0 hscroll:0 variable:null htmlText:hello world! type:input text:hello world! autoSize:none tabIndex:undefined textColor:0 backgroundColor:16777215 borderColor:0 maxscroll:2 scroll:1 filters:undefined sharpness:undefined thickness:undefined antiAliasType:undefined gridFitType:undefined [/code]

Shared Fonts in Flash IDE

Shared fonts, especially shared pixel fonts, are tricky business in the Flash IDE. Sometimes I wonder if it’s worth the effort, and whether I should just embed the fonts in each SWF. Alot of times I get blurred text when loading the pixel font from a shared library, but no blurring if the font is embedding in the swf itself. Shared fonts seem to work well with non-pixel fonts though; so if you dont need pixel fonts I would definitly use shared libraries. If you are looking at using shared fonts in your project I would recommend checking out Shared Fonts Manager.

Continue Reading

AttachMovie & Loaded Clips

Using attachMovie when you’ve loaded other clips into your movie has always been very painful. You can’t attachMovie a asset into a loaded clip that is located in the parent movieclip, and conversly you can’t attachMovie a asset in a parent that was loaded into a child.

This is extremely frusterating… but after some searching today I came across this interesting link. Using the fact that Flash likes to cache everything it can, he created a function that will load an clip that contains an asset into the movieclip you are trying to use attachMovie from. Nice idea, never thought of doing this before.

Note: this is only needed if you are loading external movieclips and want to use common assets, yes you could use shared assets but they have always given me a headache (they are a pain to create/maintain, although they may have improved since I’ve last used them), and this seemed like an interesting alternative.

Update: After attempting to use the above mentioned method I found that the code on the site I linked to wasn’t really usable for what I was trying to do, I rewrote it a bit: [code lang=”actionscript”] /* Function: attachMovieAnywhere

Description: Loads a clip (should have nothing on the stage, containing just assets) and attaches a movieclip from the loaded clip onto the stage

Arguments: file – [String] path to the SWF containing the assets callBack – [Function] function that will be called once the asset swf is loaded, and the movieclip has been attatched. The scope of the function is the attatched movieclip, and the first argument is the attatched movieclip. If you need a different scope use the class. NOTE: this does not call once the attatched movieclip has been initialized, only when it has been attatched! */ MovieClip.prototype.attachMovieAnywhere = function(file:String, idName:String, newName:String, depth:Number, initObject:Object, callBack:Function) { if(depth == undefined) depth = this.getNextHighestDepth();

var parent:MovieClip = this; var container:MovieClip = this.createEmptyMovieClip(newName, depth); var mcLoader:MovieClipLoader = new MovieClipLoader(); var listener:Object = new Object();

listener.onLoadInit = function (mc) { parent[newName] = mc.attachMovie(idName, newName, mc.getNextHighestDepth(), initObject); if(callBack)[newName], parent[newName]) }

mcLoader.addListener(listener); mcLoader.loadClip(file, container); } [/code] Here is some example code showing how it is used: [code lang=”actionscript”] attachMovieAnywhere(“asset.swf”, “aAsset”, “coolthing”, getNextHighestDepth(), {_x:-40, _y:-40}, function(mc) { if(mc == this) { // mc == this unless you use the Delegate class to change the this var trace(“They Do!”) }

// you can do initialization here mc.onRollOver = function() { trace(“over”). }

mc.onRollOut = function() { trace(“out”) } }); [/code]

Continue Reading

Adding Methods to Core Flash Classes

Every once in a while I get an email that looks like this:

I tried using your Object, Function, and String method additions. When I tried to compile I get a bunch of error messages! What do I do?!

Yup, this is because the method definitions are not in the Class definition files that flash looks at when compiling. The core class definitions that Flash looks at are located here: [code]~/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/Classes[/code] That “Classes” folder will contain all the method definitions for all core Flash classes (MovieClip, Object, Button, Color, etc).

To make my method additions compile correctly you’ll have to edit the corresponding Class definition files and add the method definitions in. So, for instance, if you wanted to use the additions you would add these method definitions to your file in the “Classes” directory referenced above: [code lang=”actionscript”] function initBroadcaster(); function addEventListener(); function removeEventListener(); function dispatchEvent(); function centerXY(x:Number, y:Number):Void; function centerY(y:Number):Void; function centerX(x:Number):Void; function isInstanceOf(); function isMemberOf(); [/code]

If you are using Flash 8, they will be spread out in two different directories “FP7” & “FP8” located in this directory: [code]~/Library/Application Support/Macromedia/Flash 8/en/Configuration/Classes[/code]

If you use mtasc you’ll have to edit the class definitions located in the “std” directory.

Continue Reading

XASH 1.2

XASH 1.2 has just been released. This release has the following enhancements.

Fixed a nil URL bug Added live (itunes-like) searching Some code cleanup/reorganization Added drag n’ drop for adding additional search paths Added the sparkle update framework


If your a Cocoa developer you may want to check out XASH’s source code, it has a nice implementation of enabling a NSTableView to have a drag n’ drop capabilities while still using NSArrayController to populate the table.

Continue Reading

XTrace: Flash Debugging Without The Flash IDE

XTrace 1.0, a replacement for the horrible trace window in the Flash IDE, was released a few days ago. Take a look at the product page for more information on how it works and how to integrate it into your flash application. This is one of the pieces to the puzzle, I’ll release the BASH script I’ve written that allows better MTASC Xcode integration as soon as possible.

I need more beta testers for the new application I’m going to be releasing, email me if your interested!

Continue Reading

Random Tid Bits

Heres some programming tid bits that really didn’t deserve their own post, so I grouped them all together into one post! 😛


We all know about the common else-if language construct that is available in almost all programming languages, but here one you might of not been aware of: the else-switch statement. [code lang=”javascript”] if(false) {

} else switch(number) { case 0: //do something break; case 1: //do something else break; default: //do default action } [/code] Actually, you can follow if with any control statement. For instance, you can have an else-return or an else-break statement. This might be old news to some programmers, but I never knew you could do that!

Declare Variables Inside a switch Statement

I never had to do this before, but recently I needed to declare some variables inside a switch statement. A little googling revealed that variable declaration inside a switch statement is possible: [code lang=”cpp”] switch(something) { case 1: { int a; //a variable is declared! } } [/code]All you have to do is enclose your case statement with brackets and you can define all the local variables you want.

Reset mySQL’s auto_increment

I love mySQL’s auto increment feature, but while developing applications using mySQL I sometimes need to reset the auto_increment counter. The follow code snippet will reset your auto_increment so the next database record id will be 0: [code lang=”sql”]alter table your_table auto_increment = 0[/code]

Text Conversion Utility

MacDevCenter has a nice article on a ‘hidden’ text conversion utility, textutil thats bundled with the os x dev tools.


Something that I’ve always hated about javascript is the lack of reusable libraries and classes. Finally their has been some movement to standardize alot of common javascript tasks, not just to post ad-hoc solutions on the various script sites out there. You can get a comprehensive list of the various libraries available here.

F-Script Anywhere

This is one of the coolest things that I’ve come across for OS X. F-Script anywhere lets you look inside a program while its running. You can call methods of objects, inspect the properties of UI elements. It’s pretty incredible. You’ll need to get the F-Script Framework before you can use the F-Script Anywhere SIMBL plug-in.

Objective-C Instance Variable Initialization

In objective-C their is no need to initialize your instance variables to nil/NULL (you normally should initialize all variables to nil/NULL, or some other initial value for reasons described in this article). This is already done for you in the alloc method of an object.

Carbon Data Types

Its hard to me to understand Carbon code well because of all the ‘opaque’ data types used by Carbon. At first glance what is ItemCount? Is it a int? An unsigned int? A long? Theirs no documentation of these data types in the Apple docs anywhere, so I went looking around to see if i could find the header files that contained the definitions for the various data types. Luckily my search was not in vain: [code]/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/[/code] The above directory contains the definitions for most common Carbon data types, the majority of common Carbon data type definitions are located in the following header file:


Initializing All Elements of a C-Array to 0

You can easily initialize all elements of a C array to zero by initializing the first element of the array to 0 using the “bracket initialization” method: [code lang=”cpp”] int intArray[1000] = {0}; [/code] The above code will initialize all 1000 elements of intArray to 0. All elements that aren’t given a initial value using “bracket initialization” are given an initial value of 0.

Continue Reading

Xash 1.1

I’ve had this hanging around for awhile now, I just haven’t had a chance to package it up and put it out there: XASH 1.1.

Alot of changes have been made in this release:

Book filtering Window position & size are saved Constraint on min left splitview width added The help window will appear automatically when XASH is ‘clicked on’ (activated) Groundwork is laid for live searching Fixed bug where nothing would appear in the left document outline Window title now represents what page you are currently viewing flash 7/flash 8 root help directory paths can now be specified by the preferences keys f7Path and f8Path You can specify additionally directorys to be searched for help files through the preference key additionalSearchPaths Redid the program structure (now their is only one .nib file containing all the objects) Added an application icon XASH is now a universal binary

I added the ability to specify the paths to your flash 7 and flash 8 help file directories along with the ability to specify additional paths to search for help files at. I was too lazy to write a GUI allowing you edit this, so if you want to change the default values your going to either have to use the defaults command line application, or Apple’s Property List Editor (included with the dev tools). Here a list of the keys that would want to edit in the com.mabwebdesign.xash.plist files located in ~/Library:

f7Path– string, path to the Flash 7’s help files directory. The default value for this is: /Users/Shared/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/HelpPanel/Help/ f8Path– string, path to the Flash 8’s help files directory. The default value for this is: /Users/Shared/Library/Application Support/Macromedia/Flash 8/en/Configuration/HelpPanel/Help/ f7Index– string, URL file path referencing the main index file Flash 7’s help files. The default value is: [code]file:///Users/Shared/Library/Application%20Support/Macromedia/Flash%208/en/Configuration/HelpPanel/Help/Welcome/Welcome_help.html[/code] f8Index– string, URL file path referencing the main index file Flash 8’s help files. The default value is: [code]file:///Users/Shared/Library/Application%20Support/Macromedia/Flash%20MX2004 /en/Configuration/HelpPanel/Help/Welcome/Welcome_help.html[/code] additionalSearchPaths– array of directory paths representing other directories to search for Flash help files at. The default value is an array with a single element whose value is: [code]~/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/HelpPanel/Help/[/code]

Please send me any feedback you may have.

Continue Reading

Xcode Actionscript Integration: The Next Step

I’ve tried the whole Eclispe setup, but I’m just too used to Xcode to really like it.

So I decided to improve the support of Actionscript/Flash Development in Xcode. In my opinion, for optimal development speed we need the following components in the Actionscript-Xcode system:

Easy MTASC compiling with optional file pre-processing support Easy documentation creation Integration of Flash debugging into Xcode’s run log Full code-sense support Flash help file access without the Flash IDE Visual layout of graphics, textfields, MC’s, and vector graphics without the Flash IDE

I already have some work done in some of these areas:

I am working on a new Xcode project template that will allow integrated pre-processing & compiling of Actionscript along with easy documentation creation. This is a huge improvement over the last method, but it still isn’t perfect. I’ve done some research to see if it would be possible to make MTASC integrate seamlessly into Xcode by writing a native Xcode plugin, its definitely possible and somebody has already done alot of reverse engineering and made a plug-in for Objective-Calm.

I’ve written a BASH script that generates a list of key words from a specified class path to be used with Xcodes code sense. Although this works, its not nearly as nice has having ‘real’ code sense, but Apple has kept their API for Xcode’s source scanner class closed preventing the creation of custom source scanners.

I released XASH a little while ago allowing Flash help file access without the IDE, it still needs alot of work; but at least its usable.

Intergrated Xcode debugging is something that I’ve always thought would be incredibly awesome, but only actually realized that it could actually be accomplished within the last few months. The basic idea is you specify a custom executable and run it within Xcode. The custom executable will be a server application which will accept XMLSocket connections and redirect all input from any XMLSocket connections into stdout. Since the server application was launched with Xcode both stdout and stderr are redirected into Xcode’s run log thus any input received from any XMLSocket connections will be displayed in the run log. I’m working on implementing the server application in Java and adding easy access to the ‘trace server’ (the executable allowing output to be shown in the run log) from my debug class. When I’m all done all you’ll need to do to redirect output to the ‘trace server’ is to call debug.initSocket() and once a socket connection is established all output send to debug.trace() will be redirected to the ‘trace server’. The Java server will support multiple connections so it can receive trace output from multiple SWF’s. Heres a screen shot of a SWF’s trace output being redirected to Xcode’s run Log:

Visual layout of graphics, textfields, etc, etc would be really cool also. A project like this would actually be possible using SWFMILL as the underlying engine to create the SWF.

I’m working on getting everything packaged up and documented so I can release it into the wild.

Continue Reading


A few weeks ago I was searching around trying to decide what documentation system to use in my Actionscript/Flash projects. There are alot of options out there, but these are the ones that I found viable for my situation:

as2api AS2Doc VisDoc NaturalDocs

As2api: overall as2api seems like a good solution but I really didn’t like the style of the documentation as2api created and the os x binary didn’t seem to work on os x.

AS2Doc: looks like a good package, but it costs money; I cant see paying for something that has a free alternative which has very similar functionality. I’d rather donate to an open-source project.

VisDoc: looked really nice– exactly what I was looking for, I was very close to buying it until I saw NaturalDocs.

NaturalDocs: this turned out to be my final choice. NaturalDocs is OSS written in pearl so it will run on any OS that supports pearl. Using NaturalDocs is easy enough and it produces very nice looking documentation. The only downside is that currently it does not support JavaDoc style comments (this is on NaturalDocs to-do list), but this really wasn’t a big deal since learning NaturalDoc style commenting was very easy.

Continue Reading