Blog

I don’t think we are ever going to see a solution for embedding fonts in ActionScript that is easy to use. In AS3 we were introduced to the use of the [Embed] tag, allowing you to embed files both from the local system, and also from exported swf files. Extra options include the option to specify the unicode character ranges, to save on file size. The best solution, is to use runtime shared libraries or make use of getDefinitionByName() to extract them out of loaded swf, however what happens if you need a textual preloader to load the font swf, and you get the fatal “Unable to transcode Font” message when using the embed tag in the flex compiler?
Well, firstly this happens because there are three font transcoders in the Flex compiler, and they all prefer TrueType fonts, and all suck (in my humble opinion). So the solution is to use the old faithful Flash IDE to handle your PostScript related font issues.
To do this, create a TextField instance inside a symbol and give it an instance name like “textField”, make sure you select the “embded fonts” option and only include the number of characters you require. Next mark the symbol for export and remember the class name (you don’t need to create a corresponding .as file for this class, one will be generated for you, also it doesn’t matter if you have the “declare stage instances” option on or off, this will be handled by for you as well).
The next step is then to use the embed tag to import this symbol (quick tip use the # symbol after the .swf to access the class name quickly e.g. [Embed (source="embeddedFields.swf#FontField")] ) and then all you need to do is instantiate the class and use inline array notation to access the TextField instance and use it like a regular textfield, like (fontFieldInstance['textField'] as TextField).text = “ta da”;
Peezy

Recently here at emak mafu we’ve been building an internal framework to help quickly get some of sites up and running, and have been taking our queues from the Flex framework, asWing and the CS3 components. The best part about this is you get to dive into many peoples code to see their best practices and how they approach the problem (and sometimes shamelessly imitate it). Sometimes you will see a little to-do here, or a quirky comment from a developer as they implement a little hack, but sometimes you begin to get a whiff of a coding smell. This is not to say these frameworks are far in advance of our own, but I’d like to share one whiff that is too pungent to ignore.
The culprit is one mx.controls.listClasses.ListBase, in particular the method collectionChangeHandler(). The first thing to mention is that this class is nearly 10,000 lines long, which is an issue in itself although with the asDoc comments it is easy to forgive this. The method collectionChangeHandler is a method which is 395 lines long, which anyone who has read Refactoring will tell you is suffering from a bad case of long method, which is recommends a method be no longer then 10 - 20 lines.
Now to totally geek out, I started to count the number of if, try.. catch, and for.. loops so I could make a better point of why the method needs refactoring, but after 36th if.. else, 3rd try.. catch and 5th for.. loop I gave up. It is impossible to decipher the functionality without chatting to the author, and in such an important base class as well, where any of this behavior may need to be overriden. Anybody else out there found any blunders?

Hey,

I thought I’d share a Ulrika moment with you all regarding FDT 3 and Debugging…

For the past few days, every spare hour I’ve had I’ve been trying to get debugging working in Eclipse using FDT 3.0 enterprise - for some reason it just wouldn’t stop at the break points, and then…. urika! so i thought I’d tell you the thing they forget to tell you……

Since the demise of Xray browser in AS3, which allowed you to drill down into objects to find their children and variables, working out the state of the application at any given time has become a nuisance, time consuming, and down right frustrating. This even forced Alex - another of our developers out of Eclipse and into Flex Builder to author flash projects - just to get the debugger feature. This was even to the sacrifice of some the amazing features of FDT such as quick assist and even eclipses templates feature.

For all others that cant seem to get the debugger to stop at the breakpoints, it seems that eclipse dosn’t like the spaces that are in the path name to the default linked library ‘playerglobal.swc’ - so a simple sym link or just by moving this swc to a place with a clean source path and wolla - DEBUGGING IS BACK! oh - dont forget to update the linked library for the current project, or you’ll be back at square one.

hope this helps a lost debugger somewhere

Russ

First of all, just installed the wp-syntax plugin, so now we can have proper example code on the blog. I can’t believe it took us so long to get it on here, seen as its pretty much ubiquitous among the developer community, I find it really useful when browsing example sites so I thought we better get it on here sharpish.
Will that in mind I thought I’d share a particular hack/workaround that I was working with last week regarding for..in loops (not to be confused with for each loops).

1
2
3
4
for (var i : * in object)
{
 
}

This works fine for native objects and arrays, but back in the day of as2 you could loop over public variables and getters in custom classes as well. Not so in as3, it simply skips the loop. As you may have guessed by the title of this post the solution is to override the default valueOf() function with an object that represents your class, for example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package {
 
	/**
	 * @author alexanderfell
	 */
	public class GeomPoint {
 
		private var _dimensionMap:Array;
 
		public function GeomPoint(newDimensions:Array) 
		{
			_dimensionMap = newDimensions;
		}
 
		public function get x():Number
		{
			return _dimensionMap["x"];
		}
		public function get y():Number
		{
			return _dimensionMap["y"];
		}
		override public function valueOf():Object
		{
			return {x:x, y:y};	
		}
	}
}

This way, we simply loop over the valueOf() instead of the the class. As a side note the code above is for a co-ordinate generation system which may require the dimensions to be labelled differently depending on which frameworks we are using (for example APE uses “px” and “py”) which is the reason for all the dimensionMap funny business, not me being unnecessarily difficult.
The eagle-eyed design pattern enthusiast may be able to see the decoration of an array here (this is just an example, the real code has an abstract class that sets the dimensions, then everything extends that abstract…. what you think I’d put all the code up here!?).

edit: damn syntax styles….

Here at Emak Mafu we’ve been working on project that for one reason or another has to be coded in AS 2.0, which is a real pain seen as I’ve recently made the jump to AS 3. In this past week my screen has seen more yelling than ever, and I thought I’d let you know why.

Debugging

Where on earth are the compile time errors in AS 2? Seriously, if your working with complex/dynamic objects, or using any sort of design patterns then you might as well go home. I would estimate that about 40% of my coding time has been spent sifting through my code looking for things that AS 3 simply would not let you code, which brings us to…

Loosely Typed Objects

So it seems that without the mx library, AS 2 has about 4 classes (ok, maybe slightly more) which makes it really hard to predict the inputs and output of various core components. Worse still it seems that every plug-in and framework under to sun has been built with no extension in mind, at least with AS 3 you’d usually start off by extending the…

EventDispatcher

Thank god for the mx EventDispatcher, I think I would have gone crazy if I had to keep passing references in and out of singletons, where’s the cohesion in that? Its not the best though, and the number of times I’ve tried to dispatch an event from a MovieClip (errh, no Sprites?) or Object without first initializing it with an EventDispatcher, why its like trying to invoke Quicksilver on someone else’s mac, only to find there not using it (its doubly embarrassing if their using a PC). And speaking of Sprites….

CreateEmptyMovieClip()

I hate this, I really, really hate this. Lets say I want to create a MovieClip, and store a reference to that MovieClip. Here we go…
var mc:MovieClip = _scope.createEmptyMovieClip("mc", _scope.getNextHighestDepth());
Do any of you clever communication experts see the redundancy? I have a variable called mc, but I also specify a string name “mc” as well. Why? I don’t know, well I guess I do, its because the stage and variable components of the MovieClip model are not loosely coupled i.e. to create a MovieClip, you have to place it on the stage there is none of this lovely var mySprite:Sprite = new Sprite(); business that we have in AS 3. The most frustrating thing about this is, is that if you are naming clips in a loop, you may inadvertently confuse your variables, which is again all about the debugging. I suppose if you had to sum it up, you could say that its a…

Better Language

Because AS 3 is more like Java, you tend to think in a more OOP way, which in turn makes you think about things a bit differently. Instead of rushing in and hacking together a solution, you tend to think about how you are going to extend and re-use your code. Of course, this is not to say people didn’t do this in AS 2, it just feels more natural in AS 3 and it shows. You can tell when your coding in AS 2 that they haven’t gone the whole-hog. Some features in particular feel like they’ve been tacked on (the MovieClip.beginFill() as opposed to Sprite.graphics.beginFill() for example), creating some kind of mad-max-esque contraption.

I hope that this persuades some of you who are reading this to make the move to AS 3, best thing I ever did (coding wise, I’m not that sad).

Mac OS Leopard and Flash Tracer

November 12th, 2007

I upgraded to Leopard onto my mac the other day, and it broke the flash tracer in Firefox….. found out that Leopard reinstalls the normal flash player for some reason - so you need to get the debug version back again. The solution might sound obvious (sometimes this can be the problem in itself), but without that flash tracer, my days get alot harder! so i thought i would share my find

So we got sent some t-shirts from Adobe last week, which was really exciting, apart from the fact that out of 15 there were 2 medium, 10 large, and 3 “goliath XXXXXL with extra cream please”. Me and Hugh are modeling the mens in the latter size…

I would love to get some feedback on my original post about our word press blogs going wierd. Its now effected out flex user group site. This site to my knowlege hasnt any changes to it in the last month, and then bang! it starts complaining about duplicate entries.

I have now changed all primary keys to autoIncrement in every table. This has solved the problem, but its a strange fix to do to such a huge application such as word press. would love to know your thoughts

wordPress bug?

October 1st, 2007

I’m not sure if this is a bug due to word press, or if one of our team sneaked into the database and did something ugly becasue one day both (designspam) of our blogs started playing up giving this error:

INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES (’59′,’_utw_tags_0′,’a:0:{}’)

after a while scratching my head and looking for answers - i wasnt really coming up with much, all the other blogs were saying that the tables might be currupt or the word press want upgraded propery, but none of these were relevant, so i decided to get knee deep in the database myself.

After creating many test blogs and databases, and updating them with our blog content - i noticed that the error only happens when an entry with the ID of 0 exists in either the wp_posts table or the wp_postmeta table. getting rid of this entry seemed to stabilize the system when creating a new blog…. until you added another one, and it tries adding it as zero again. So the whole problem rests on the fact that as soon as an entry exists in the database with ID 0, then things start going a bit wrong.

I solved the problem by changing the ID structure to auto_incremement, and zero dosnt get a looking, but fear this is a hack that might come back to hurt me later on.

I posted this article for two reasons:
1. To help some poor soul like me speed their day up a bit
2. Maybe get some feedback if this method has been tried and tested before

either way, would love to hear something on this matter