Posted by: edsyrett | 17 October 2008

Build all your stylesheets…every time…

We have a whole bunch of stylesheets in our project.  Unfortunately, our release build had the filenames hard coded in, i.e. it was only building specific stylesheets. So when somebody added new css files, they didn’t get included in the build.  

There must be a way to automatically pick up all the css files and build them, we thought.  And here it is….

This tip relies on the foreach and propertyregexp Ant tasks from the ant-contrib library.  You can download the ant-contrib distro from here.  I found the easiest way to make use of this library is to just copy ant-contrib.jar to your Ant lib directory.

In your build file, simply add the following line, which will enable Ant to access the new tasks:

<taskdef resource="net/sf/antcontrib/antlib.xml"/>

and here’s the interesting bit:

<target name="build-debug">
    <foreach param="filename.css" target="css-build-debug">
        <path>
            <fileset dir="${basedir}">
                <include name="*.css"/>
	    </fileset>
        </path>
    </foreach>
</target>

<target name="css-build-debug">
    <echo>Building stylesheet ${filename.css} (DEBUG)</echo>

    <!-- Extract the base of the filename, i.e. for c:\Development\tls\...\v1.0\kn.css" we want "kn" -->
    <propertyregex property="basename" input="${filename.css}" regexp=".*\\(.*)\.css" select="\1"/>

    <java jar="${mxmlc.jar}" dir="${basedir}" failonerror="true" fork="true" maxmemory="256m">
      	<arg line="+flexlib='${flexsdk.frameworks.dir}'"/>
	<arg line="${filename.css}"/>
        <arg line="-output 'bin/${basename}.swf'"/>
    </java>
</target>

The <foreach> task is provided by the Ant-contrib library – in this case it iterates through all the files picked out by the <fileset> task and passes them to the target in the property filename.css.

The <propertyregex> task is another one from the Ant-contrib library.  This takes an input property, in this case filename.css,  performs a regex search for a substring, and puts the result back into another property, basename

The clever bit is the actual regular expression – all it really does is extract the filename without the extension from filename.css.  We need this to be able to pass in the name of the output swf.

For those of you who love your regular expressions, here’s a synopsis of how it works:

  • .* – jump over any characters until…
  • \\ – .. you find a backslash.
  • (.*)\.css – Look for as sequence that ends in “.css”, with any characters before it.  Track backwards up to the previous search token (in this case a backslash) and put all the characters between this backslash and the “.css” in a group.
  • The value of the select attribute in the propertyregexp task defines which group is returned and copied to the basename property.
  • …and that’s it….

    Posted by: edsyrett | 24 September 2008

    ActionScript 3 (with a bit of Visual Basic thrown in…)

    Well you could have knocked me over with a feather….

    Here’s a bit of code that I just compiled with the Flex 3.1 SDK:

    var person : Person = new Person();
        
    with (person)
    {
        name = "Ed";
        age = 44;
    }

    Anyone who has done any Visual Basic will instantly recognise this as a standard construct.  But it has really been kept quiet in ActionScript 3.  It’s certainly not a construct you’d normally associate with any Object Oriented language like ActionScript and its ancestors like JavaScript and C++.  It seems to have been kept quiet by the Adobe developers – I couldn’t find anything in the documentation (although to be fair it’s difficult to filter out all the occurrences of “with”), and I couldn’t find any usage of it in the SDK source code.

    I found out about this on Vladimir Angelov’s blog here.  This lucky guy has managed to kick off his own blog and immediately produce two very informative posts.  Well done Vladimir.

    Posted by: edsyrett | 22 September 2008

    Using Conditional Compilation to detect debug mode

    We just fell down a huge hole….

    But luckily there was a ladder to get us out.

    Have a look at this code:

    private function get debug():Boolean { var debug:Boolean = false; // Find out whether or not we are running the debug swf simply by looking // for it in the url. THIS ONLY WORKS FOR Flex2 !!! debug = (this.url.indexOf("-debug.swf") > 0) ? true : false ; // test for Flex 3 by looking for the debug symbols in the app if (debug == false) { debug = getDebugFlag(); } return debug; } private function getDebugFlag():Boolean {     var debugMode:Boolean = false;     var e:Error = new Error();     var s:String = e.getStackTrace();     var i:int = s.indexOf("getDebugFlag");     if (s.charAt(i + 14) == '[')     {         debugMode = true;     }    return debugMode; }

    The intent of this code is to tell you whether or not you have a “debug” build, i.e. if you have debug symbols in the swf.

    We used to use this to detect non-debug builds and then pull off a trick to embed the SVN release in the filename of the released swf.   The reason for this is that we found that various proxies and caches would hold on to copies of the swfs, and when we did an update everybody wondered why they didn’t see any changes.   Drop me a comment if you’re wondering what I’m on about or you want to know more…

    But this code has one real, big-time problem.

    getStackTrace() returns null if you run it in the non-debug Flash Player.  And guess what happens when you try to dereference the null value held in s?  In the non-debug Player, you won’t get any error messages – everything will just fail silently.

    So this code had to go.   Instead, we’re now using Conditional Compilation.  For ageing C++ hackers like me, this is standard fare, and luckily ActionScript 3 provides this facility.

    Here’s our revised function that simply returns a boolean:

    private function get debug():Boolean {     var debug:Boolean = false;     CONFIG::debug     {     // If CONFIG::debug is defined as true, this line of         // code gets executed and we overwrite the original value.         debug = true;     }     return debug; }

    A bit simpler isn’t it.   The bit inside CONFIG::debug is included if you specify:

    -define=CONFIG::debug,true

    in the compiler flags.  So in the flags for Flex Builder, its true, and in our Ant scripts for release builds, it’s false.

    Easy.

    I thank you.

    And the moral of the story is…

    Test your apps in the non-debug version of Flash Player

    Posted by: edsyrett | 22 September 2008

    Google Geo Developers

    It’s always nice to meet up with the guys responsible for the tools you use day in, day out.  I went to a little meet of a bunch of developers at the Google UK office in Victoria.   A guy called Mano Marks organised the meeting and his blog entry is here.

    It wasn’t an earth-shatteringly informative session, more along the lines of “meet the guys”.

    I made sure I told Mano about the printing issue with the Flash API – basically you can’t run an effect over or print the map control because they both go off to the Google server and request the bitmaps, which results in a Security Sandbox Violation.

    Anyway…I’m in the picture on Mano’s blog entry….well, sort of… I’m in the shadows down to the right of second shot….

    Posted by: edsyrett | 8 September 2008

    Microsoft uses Flash to promote Vista

    Despite that fact that Microsoft has SilverLight, its own competitor to Flash, Microsoft still chooses to use Flash to put a video of Bill Gates and Jerry Seinfeld in a shoe shop.  

    Whatever the technology, the movie just makes me laugh…..

    Jerry:   “Is that your toe?”

    Bill:     “No”

    Jerry    “What is it?”

    Bill      “Leather”

    The look that Bill gives Jerry at this point just cracks me up.   In my opinion it goes something like this…

    If you worked for me at Microsoft I would have told you that you were a complete idiot and to get out my office….

    Posted by: edsyrett | 2 September 2008

    Google Chrome

    I’ve had FireFox crank up processor usage to 80% and hang.  I had to reboot my machine a couple of times.   And once you have the tabs, the link bar, the navigation toolbar, and the title bar of the window itself, that’s screen real-estate that I could use.

    I’m a big Google user – email, calendar, reader, bookmarks, notebook and docs are all right there on my iGoogle page.  I like the UI and how it all fits together.

    Today, I’m reading the BBC News page, and there’s an article about Google Chrome.  Eventually, the links lead to this comic book.

    I have to say I’m really looking forward to getting my hands on Chrome.   If it stops buggy web pages bringing my whole browser (and potentially my pc) down, then I’m in.  I like the sound of the individual tabs and plugins being in their own process, and the idea of Precise Garbage collection, and the fact that Google already have access to the list of the most populate websites across the whole world so that they can test with them.

    Gimme Chrome…..

    Posted by: edsyrett | 2 September 2008

    Code Signing in Adobe AIR

    More by luck than design, I’ve managed to avoid getting into the scary world of code certificates up to now.

    But now AIR requires you to sign your app with a certificate from a trusted authority. OK, that’s enough jargon for my blog…here’s a great article I found via Flex.org that goes into a bit of the background, whys, hows, etc.

    Code Signing In Adobe AIR by Oliver Goldman, Senior Computer Scientist at Adobe

    Posted by: edsyrett | 30 August 2008

    Update on Google Maps

    Now I’ve created an ActionScript component that wraps the Google Maps API.  It only took about a days work, but the end result is that I’ve got a component that takes a list of addresses plus their lattitude and longitude, and show the following information:

    • A map showing all the points
    • A list of the addresses
    • A list of directions through through each of the locations
    • A “trip list” that shows the estimated departure and arrival times at each stop, including a Dwell Time, i.e. the length of time spent at each stop.

    On each list you can click on an item and the map will centre on the location for the item.  For the directions, this means centering on the actual point the direction refers to, i.e. if it says “turn left at the roundabout” the map is centred on the roundabout…:-D

    But, as usual, there were a few holes to fall into….

    The Dreaded DEBUG Overlay

    I saw quite a few posts from people moaning about not being able to get rid of the dirty great “DEBUG” on the map.  Imagine you’re doing a demo of mapping to somebody – you definitely don’t want pesky “DEBUG” all over your map do you?

    We fiddled about for a while before finally figuring it out.  You can plug in either the domain name of your webserver, or if you’re running from a local webserver, the IP address of your machine, including the port if it’s not 80.  So generating a key for “http://xxx.xxx.xxx.xxx:8080 will get rid of “DEBUG” on your maps.  However, “http://localhost:8080&#8221; didn’t.

    Effects On Maps

    You can’t run an effect on a Google Map control after it has initialised – you’ll get a Security Sandbox Violation.

    The reason for this seems to be that the effect will try to get hold of the bitmap for the maps independently of the map component.  As the Google maps site doesn’t have a crossdomain.xml file this is doomed to failure. Sooner or later we’ll have to find a way around this as all our windows appear with an Iris effect and we don’t really want to turn this off just for our map window.  I’ll look at hiding the map while the effect is playing and post back here if I get anywhere…

    This problem also applies to printing as it’s pretty much the same scenario.  There’s a feature request here at Google Code to allow printing.

    As I mentioned in a previous post, I’ve already had a play with the HTML/Java maps interface, and I think that took me a week to get a list down the left and a map with points on it.  I’ve already achieved over double the amount of functionality in under two days with the Flex API so that should give you some idea of the potential of this API.

    Thanks to Google….

    Posted by: edsyrett | 26 August 2008

    Google Maps

    I work in a company who’s main job is to get stuff from one place to another. So you can imagine that it might be a good idea to show people where the stuff is going. When my Guvnor said “could you have a look at Google Maps API for ActionScript” I was happy to oblige. The main Developer Guide is here, and there is a ton of demos here.

    I’ve already had a go with the first maps API for JavaScript, so I was off to head start. But it only took a couple of hours to get a map up and programmatically create a couple of markers and centre and zoom the map on those markers.

    And the icing on the cake is that sweet taste of Free-ness…

    Posted by: edsyrett | 26 August 2008

    Flex 4 and Flash Player 10

    This video here was recorded at 360Flex on Day 1 and it’s the keynote speech from Mark Anders, Senior Principal Scientist at Adobe, plus a number of other speakers talking about various things.   It’s over an hour long, so get yourself a beer, sit back and be amazed….

    « Newer Posts - Older Posts »

    Categories