Path to Enlightenment
July 9, 2010
I’m a big fan of Chet Haase and his brilliant blog Codedependent. He makes very entertaining instructional videos about coding on the Flex 4 framework. I occasionally spend some time on his blog getting to know the new features in the Flex 4 framework. And time and time again he has managed to motivate me to get back to work and use my skills in a playful manner.
A while a go I watched this gripping and suspenseful video about creating a simple drawing application. The video talks about the new “Path” object in Flex 4. The Path object is an easy tool to save and manipulate line data. (This simple demo uses only simple straight line segments but this object could be used for bezier curves as well.)
Anyway I was fascinated by the small amount of code needed for this application. I downloaded the code and played with it. Here’s my interpretation of the Path to Enlightenment. It’s in the spirit of “less is more”. Draw some lines and wait a few seconds to see what I mean. Your lines will be enlighted and stripped down to their bare essentials.
The demo (press your left mouse button and draw by moving your mouse)
The source
Unexpected exception encountered while reading font file
October 18, 2009
I just had a weird unexpected exception thrown by the Flex 3.4 compiler on an existing ActionScript 3.0 project that always compiled without a problem.
exception during transcoding: Unexpected exception encountered while reading font file 'F.ttf' unable to build font 'F' Unable to transcode assets/F.ttf
Luckily I found solution via Google. Thanks Crazy Flexer “pixelfreak” adding -managers flash.fonts.AFEFontManager as an additional compiler argument fixed the build process.
Hope this blog post helps people that encounter the same issue.
FlickrPickrTickr
April 16, 2008
I’m a huge fan of fototickr , but I always wished I could use it to tick my own Flickr photos and I mean even the non-public (friends/family) ones. So I wrote myself an application that can!
I present FlickrPickrTickr.
When you load the page for the first time, you’ll be directed to a Flickr page that asks you to allow the app read access to all your Flickr photos. The next time you visit FlickrPickrTickr it will have remembered this for you. Upon you agreeing with read access, FlickrPickrTickr will start ticking your photo’s. (In my case all 7602 of them.) But you can narrow the selection down by using the pickr (click the pickr button) to specify which pictures you want to see. At the moment you can specify tags (comma separated) and specify whether you want to see the pictures with “all” or “any” of the tags specified. But I’m probably gonna extend the options in the near future.
Feel free to give me feedback.
By the way, the application is written in Flex. It’s an ActionScript 3.0 project based on the free as3flickrlib.
Parameters for a Flash 9 ActionScript 3 SWF
July 6, 2007
Recently I wrote a blog post about the differences between ActionScript 3.0 and ActionScript 2.0. One major difference that I found and dealt with had been lost in my unordered notes of what I wanted to write about;
Passing parameters to Flash.
Why would you want to that? Consider the case that your website consists of one giant swf file (and there are valuable reasons to have such a website). Off course the swf will probably be embedded inside a HTML page that links the swf content to some meta data and offers some alternative HTML content for the visitor that have no Flash plugin for their browser, but the content that you want to show to the visitor is all trapped inside that swf file. If for example you had blog content inside that swf, it would kind of suck that you have no means for giving friends URLs to directly jump to a specific blog post inside that swf similar to what you achieve with permalinks in HTML blogs. (I can for example give people the hyperlinks to blogging-in-flash or findability-and-linkability-with-flash to directly point them to what I want them to read about.) And this is just one example of why you would want a way of “indexing your swf”/”generate your swf based on parameters”.
So here it is then. A short explanation of implementing parameter passing to an ActionScript 3.0 swf. It still is as simple as having your browser request the swf file with extra parameters folowing the name of the file. Like this; name_of_your.swf?param1=value1¶m2=value2¶m3=value3 etc… this part hasn’t changed. But getting access to the passed parameters has. In ActionScript 2 you used to have global access to the parameters as they where added as variables to the _root namespace. Now it’s slightly different, they’re now stored in the loaderInfo of the Stage object. (So it’s only accessible from the Stage object itself or members of it’s display tree.
Here’s example code reading the variables;
var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
//do something with this information
}
Something else
There’s something else that slightly touches this subject. Use the Adobe Flash Player version detection kit. The flash 9 player is taken over the old players but not everyone is having the new player yet. Be sure to detect this and gently notify your visitors of the need to update their Flash plugin. That’s so much better then seeing nothing or an incorrectly functioning website! The kit provides of examples of it’s use but it might confuse you of where to insert the Flash parameters into the JavaScript function call that generates the embedded Flash object. Just add the parameters in the src string tuple (‘src’, ‘your_swf_location‘), you can omit the .swf file extension here.
For example this is the javascript (generated from a server side script) function call that embeds the Studio Roosegaarde 2.0 swf with parameter blog_item(=15);
if(hasRightVersion) { // if we’ve detected an acceptable version
// embed the flash movie
AC_FL_RunContent(
‘width’, ’100%’,
‘height’, ’100%’,
‘src‘, ‘StudioRoosegaarde2?blog_item=15‘,
‘quality’, ‘best’,
‘pluginspage’, ‘http://www.macromedia.com/go/getflashplayer’,
‘name’, ‘StudioRoosegaarde2′,
‘allowScriptAccess’,'sameDomain’,
‘allowFullScreen’,'true’
); //end AC code
}
Studio Roosegaarde – Daan Roosegaarde’s new home
October 2, 2006
We’re proud to present, it took us a while but here it finally is:
It’s been this project that kept me, Sylvia and Daan busy with Flash for the last few months. Have a look at it and tell us what you think of it. Be sure to use the latest version of Flash for the best results. https://www.macromedia.com/go/getflashplayer
Studio Roosegaarde isn’t completely finished yet, but it’s close to completion, if you give us good recommendations, they might make it into the “final” website!
We are particularly proud of:
The “blog”.
Read here and here if you want to know more about it.

The Scroller/Rolodex.
A giant rolodex, that troughout the website, takes on different forms and behaviours, sometimes reacting to your mouse, sometimes moving by it’s own will.

The Lines
A set of lines connects you with everything there’s to know about Daan Roosegaarde, Studio Roosegaarde and his Projects. In the near future the lines will bring you project movies.

The search function
The search function allows you to quickly find anything you might want to know about Daan.

And much much more
For Sylvia and me this website is has been a really interesting adventure. It’s unbelievable how far the website has deviated from our initial plans. It has become better then we had dreamed of. During the process of building the website we kept a Blog of the process. The initial plans and sketches are so ugly and unfriendly in comparison to what we have now, it’s scary. But I’m really glad that several times during the building process we’ve had the strength to throw away plans and ideas, leaving the comfort of exactly knowing where and how we wanted to end, and trying more exciting/challenging paths to an unclear goal. This might sound a bit vague to you, maybe I will later post an example of an older version of Studio Roosegaarde, so you can see the radical changes it’s gone through. (I have to discuss this with Sylvia and Daan first.)
Stay tuned to what’s going on
If you want to stay tuned to what’s going on, subscribe your self to Studio Roosegaarde’s RSS feed.
Creating TextFields with embedded fonts from a loop
September 21, 2006
uncleunvoid asked me to help him construct a loop that generates TextFields that make use of an embedded font. I thought this should be easy (easy in a relative sense, building things in Flash is never easy) but I did not succeed on my first try. I’ve become accustomed to the fact that the obvious solutions often do not work and that questioning that is a useless waste of time. Finding solutions to your Flash problems is a process of non-rational trial en error testing. Today, through luck, my second attempt succeeded and here is the code that I put in the first frame of a empty .fla file;
stop();
var textFormat = new TextFormat();
textFormat.font = “MyEmbeddedFont”;for(var i:Number = 0 ; i < 10 ; i++)
{
for(var j:Number = 0; j < 10; j++)
{var textFieldName:String = “test “+i+”_”+j;
_root.createTextField(textFieldName, _root.getNextHighestDepth(), i*50, j*30, 50, 30);
_root[textFieldName].text = textFieldName;
_root[textFieldName].embedFonts = true;
_root[textFieldName].setTextFormat(textFormat);}
}
Now, the crucial thing to make this work is to have an embedded font that is “exported for actionscript” with the identifier “MyEmbeddedFont”.

If you embedded and exported your font the right way, your result should look similar to this. (I used a “Georgia” font).

Hope this helps! If not let me know.
How to create pop-up browser windows in Flash
September 20, 2006
Yesterday I did some experiments with trying to control the appearance of a pop-up window “created in Flash”. Well I started out knowing that it’s impossible to directly control the appearance of browser windows created from Flash, but I had some hope that calling javascript from Flash would do the trick. I soon found out that there’s the fscommand function to enable the programmer to call javascript functions defined in the page that embeds the Flash movie and I managed to implement what I wished for. Here’s my implementation using fscommand, I think it’s interesting enough to share with you because being able to call javascript from inside a Flash movie must have some powerfull applications. But do not copy this code if you want to use it for opening pop-up windows, read on, because I’ve got better tips for doing that particular thing.
Here is the JavaScript code that you put into your HTML <head>
<script type=”text/javascript”>
<!–
var isInternetExplorer = navigator.appName.indexOf(“Microsoft”) != -1;
// Handle all the FSCommand messages in a Flash movie.
function StudioRoosegaarde_DoFSCommand(command, args) {
if(command == “openURL”)
window.open(args,”_blank”,”toolbar=0, location=0, directories=0, status=0, scrollbars=0, menubar=0″);
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf(“Microsoft”) != -1 && navigator.userAgent.indexOf(“Windows”) != -1 && navigator.userAgent.indexOf(“Windows 3.1″) == -1) {
document.write(‘<script language=\”VBScript\”\>\n’);
document.write(‘On Error Resume Next\n’);
document.write(‘Sub StudioRoosegaarde_FSCommand(ByVal command, ByVal args)\n’);
document.write(‘ Call StudioRoosegaarde_DoFSCommand(command, args)\n’);
document.write(‘End Sub\n’);
document.write(‘</script\>\n’);
}
//–>
</script>
But you should replace the occurrences of StudioRoosegaarde with your Movie id/name. And if you want to play save, choose “Flash with FSCommand” in the HTML settings of the Flash publish settings dialog, and the right code will be generated for you.

Your ActionScript code should look similar to this.
/**
** openURL
*/
function openURL(earl:String)
{
fscommand(“openURL”,earl);
}
So this worked for me and was way cooler then having popups open in windows surrounded by toolbars, but I wasn’t completely happy yet. After some testing in different browser (Really important in web-development!) I discovered some oddities with versions of FireFox. With FireFox 2.0b2 the movie calling the JavaScript would stall. Unacceptable!
Today I discovered a Technote on Adobe’s website that summarizes three ways to “create” a pop-up windows from Flash. Two of them I had considered before, but the middle one “geturljs” was new for me. The article states that this solution is “simple and consistent”. This technote put me on the right track to finding what I think is the best possible solution. This article on Flash-DB.com that I found using Google goes into the details of the solution. They even provide you with a link to an application that can generate the required actionscript and javascript code for you based on your particular parameters!
Here’s the code that works for me!
/**
** openURL
*/
function openURL(earl:String,width:Number,height:Number)
{
getURL (“javascript:NewWindow=window.open(‘”+earl+”‘, ‘newWin’, ‘width=”+width+”px, height=”+height+”px left=0, top=0, toolbar=No, location=No, scrollbars=No, status=No, resizable=No, fullscreen=No’); NewWindow.focus(); void(0);”);
}
ActionScript Mouse Events and Delegation
September 19, 2006
If you’ve used Flash MovieClips events onRollOver, onRollOut, onRelease, onReleaseOutside or onPress you’ve probably encountered the annoying little Flash shortcoming, that you can’t define mouse event-handlers on MovieClips contained inside MovieClips that have a mouse event defined.
Suppose you have something like this:
this.onRelease = doSomething;
this.createEmptyMovieClip(“childMC”,this.getNextHighestDepth());
var childMC:MovieClip = this["childMC"];
//Add some code to put something inside childMC
childMC.onRollOver = doSomethingElse;
The code in the function doSomethingElse will never be reached, because all mouse events are “caught” by childMC’s parent MovieClip.
A workaround that I use is to check in the parent functions whether the events apply to children.
Here’s an example for the onRelease event:
this.onRelease = function()
{
if (childMC.hitTest(_root._xmouse, _root._ymouse, true)) {
doSomethingElse();
}
}
The MovieClip function hitTest is used to test whether the mouse is hovering above the childMC when released. hitTest takes as arguments the x and y coordinates of the mouse relative to the _root MovieClip and a boolean that specifies whether to do the hitTest using the actual MovieClip shape (true) or just it’s bounding box (false).
Delegation
Sometimes you may want to base the logic in a mouse handling event on data that’s stored in another MovieClip, of course you can expose the decisions variables by making them public variables and accessing them through some relative path like _parent.var1 or this.childMC.var1 but a cleaner solution might be using Flash delegate creator available in Flash 8 professional. I learned how to use it through this Delegate tutorial. With delegates you can define mouse event handlers that execute in a object scope other then the MovieClip object scope on which they are defined! This how I used it for example. I had a ‘parent’ MovieClip showing a JPG image. In the MovieClip was ‘child’ MovieClip called zoomer, that when pressed should open a new browser window containing a high-res version of the JPG. I sensed that it would be better program design to have the knowledge about the image low-res and high-res version in the ‘parent’ MovieClip. Without use of a Delegate I should have either copied the knowledge of the high-res JPG to the child MovieClip or exposed that knowledge through the parents public interface. In my humble opinion the delegate approach is the cleanest, really leaving all the data and logic concerning JPG’s in the parent MovieClip.
Here’s how I used the delegate functionality:
import mx.utils.Delegate;
zoomer.onRelease = zoomer.onReleaseOutside = Delegate.create(this, handleOnRelease);
Aligning htmlText inside Flash TextField
September 7, 2006
Here is again a post in a series of posts documenting Flash and ActionScript behaviours I wish I had known about before finding it out the hard way, that is finding it out after a long time of trials and errors. Today I was trying to adjust the alignment of htmlText insinde a Flash TextField. Since the TextField has no align property by itself, I figured that using a TextFormat object and setting it’s align property would do the trick. I was wrong.
This was how I tried to align the htmlText in my TextField;
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.align = “right”;
myTextField.setTextFormat(myTextFormat);
But for reasons that are unclear to me, this does not work. After long research I found a way that does work. It’s by using the TextField.autoSize property. “autoSize” is a name that in my humble opinion doesn’t convey much of it’s purpose. But here is what Adobe says it does. In a nutshell, the autoSize property helps you set alignment and resizing behaviour in one statement. To say autoSize=”right” is equal to instructing the TextField to align it’s text to the right and re-size the TextField to the left if needed. So here is how I used it;
myTextField.autoSize = “right”;
Piece of cake once you know it.
ActionScript Object Duplication
September 4, 2006
Yesterday I posted how to properly copy an ActionScript Array.
Here is an recursive implementation that allows to deep-copy objects (other then MovieClips);
/// duplicate any given Object (not MCs)
Object.prototype.copy = function()
{var _t = new this.__proto__.constructor(this) ;
for(var i in this)
{if(typeof this[i] == “object”)
_t[i] = this[i].copy()
else
_t[i] = this[i];
}
return _t;
};
ASSetPropFlags(Object.prototype,["copy"],1);
I found this code here. Thanks klitze7-c004, I will use this method from now on to copy Arrays , this way I’m sure that the contents get copied as well.
Of course this is how it’s used.
var x:Array = new Array(“1″,”2″,”3″,{a:1,b:2});
var y:Array = x.copy();



