Wednesday, 23 November 2011

Notch vs Yogscast

There has been much drama lately over in the Minecraft community due to a series of Twitter posts by Markus Persson. Read the thread at Minecraft Forum and TotalBiscuit's reply to get an idea about what's going on.
There have been several points made and I'd like to comment on a few:

Tuesday, 22 November 2011

Push Blogger's Sidebar Ad Down to the Bottom

Good Bye Old Design!
While changing the design of my blog from the old copper themed mess to this new clean template, I was carrying out numerous changes to the CSS of the template.

I made myself busy changing the colours of everything, enlarging and shrinking text, and tapping the refresh button on my browser to check things were peachy.

Hello New Design!
After having gone through many templates, I settled on the design which you can see on this page. 'Clean', I thought and I especially made sure that I praised myself enough for the ninja page buttons which were done so that it didn't form a boring old bar. As my eyes roamed around the screen, I gasped when I took a glimpse of the AdSense advertisement at the bottom of the sidebar.

There were a few problems to it:
  1. The advertisement was placed right below the last widget, with no breathing space.
  2. Having the advertisement in an easy-to-view location is beneficial for increased exposure of the ad but I prefer a more discreet placement. At the time, my sidebar ad was glaring at me in the face!

What I wanted was for the advertisement to be placed at the bottom of the sidebar pane and effectively at the bottom of the page, disregarding the height of the page (which changes depending on content). This would allow ads to be viewed after the reader finishes reading a post, not before.

Tuesday, 15 November 2011

AS2 | Long Click Detection

This article deals with Long Click (aka Long Press aka Press and Hold) detection implementation using ActionScript 2.
Prerequisite: AS2 | Object.addProperty

When working with a touch screen UI, one has to often consider what someone else would intuitively do when dealing with the UI. Naturally, people tend to fall back to experience from older analogue devices which provide tactile feedback.

Think back to a few years ago, when the first Walkmans were becoming hip. You'd see teenagers walking down the street with a pair of earphones in their ears, clutching onto a small grey device. Looking closer, you would notice the spinning wheels of a cassette tape. These devices were in no way complex but they did what they were built to do: play music from cassette tapes.

Part of the playback relied on seeking which was done by pressing the fast forward or rewind keys. If you pressed the keys for a short time, the tape would rewind or fast forward just a little bit. If you held on for a longer moment, hearing the whirring in your earphones, you would be sent further back or forwards in the cassette.

The Need for better Long Click Detection

When designing a music UI, it is often expected that pressing the fast forward or rewind keys briefly will change the track being played. It is also expected that holding onto the forward or rewind keys will let you seek within the current track.

This feature is by no means difficult to write with ActionScript 2. In fact, I will do that now for a MovieClip button named mcPrev:
var count:Number = 0;

mcPrev.onPress = function (Void):Void
    this.onEnterFrame = function (Void):Void
        if ( count < 10 ) {

mcPrev.onRelease = function (Void):Void
    if ( count <= 10 )
    count = 0;
    delete this.onEnterFrame;
The code above starts counting up to 10 once you press the button. When it reaches 10, it starts rewinding the current track. When the button is released, the code checks if the counting had been done above 10 and if not, changes the current track to the previously played track.

It's all very simple and Just Works.

What happens though when you want to get that working for 10 different clips?

  • First off, you can't use the variable count like I do, it must be tied to the MovieClip since it would be over-written by other actions.
  • Secondly, you would end up with hundreds of un-necessary lines of code.
  • Thirdly, you would get confused about how and when you should be using MovieClip.onEnterFrame. This is because the code above relies on the said event.
  • Fourthly, you would get tired of writing this piece of code, having to alter it ever so slightly as you increase the usage of it.

Would it not simply rock for you to be able to do the following?
mcPrev.onLongClick = function (Void):Void

mcPrev.onShortClick = function (Void):Void

AS2 | Object.addProperty

The most useful method I have thus far encountered while programming in ActionScript 2.0, is Object.addProperty. I would like to explain why this is so and how the method works.

Objects (and Arrays)

In ActionScript, the Object type/class is used frequently. An Object is used differently in different situations. In the object-oriented programming sense, Objects are instances of a Class. In a very basic sense, Objects are Arrays where the indices are named.

In both Arrays and Objects, any data type can be put into a new slot. In an Array, you must pick a spot based on the available integer index slots while in an Object, you must specify the String index.
function Three (Void):Number
    return 3;

var my_array:Array = [
                       1,                 // Number
                       "Two",             // String
                       Three              // Function

var my_object:Object = {
                         one: 1,          // Number
                         two: "Two",      // String
                         three: Three     // Function

Both arrays and objects are useful in different ways.

Since the integer indices are important for arrays, it is essentially an ordered stack where you can .push or .sort the elements among other methods. This is very useful for queues for example, where the order of a list is very important.

Objects on the other hand have the advantage that the elements can be referred to very easily.
trace( my_object[ "two" ] );
// Traces "Two"

trace( my_object.two );
// Traces "Two"

As you can see in the example above, you can refer to objects like you do in an array and also as a "." concatenated string where you have some sort of a tree structure starting from the top object. When you use any method in ActionScript, you are using this tree-like structured syntax and this syntax is simply wonderful. At the most basic level, it gives your code a more modular feeling, letting you differentiate between associated bits of code. At a more advanced level, you are able to use the same methods or properties for many different objects, making programming in general easier.

Thursday, 10 November 2011

Skyrim and musings about putting The Matrix in an MMO

Note: These are just the musings of an idiot. If you find the ideas ridiculous, please pass by.

Friday, 4 November 2011

Benefits of a Custom UCI Launcher

In my previous post concerning the way UCIs are implemented in Cowon's mp4 players, I touched upon the potential of the UCI launcher movie (or rather, the shortcomings). I would like to discuss more about what the launcher does and would like to introduce to you what one could do to improve your Cowon experience.

The different default UCIs of the Cowon J3, served to you by the launcher (Image courtesy of Cowon)

Wednesday, 2 November 2011

Cowon's Flash UCI Structure

As mentioned in my previous post about Cowon's support for UCIs and the need for a UCI framework, users of Cowon's mp4 players can apply community-made custom user interfaces to their players with a few easy steps. Designing those interfaces requires a lot of work, however.

Cowon's UCI File Structure
If you have used any of the UCIs, or CCUIs (Community-Created User Interfaces) as I like to say, you will know that you can usually install your own UCIs by simply dropping a few .swf files into the folder, System/Flash UI/ and that the UCI settings can usually be found in System/Flash UI/SOL/ as files ending with the extension, .sol.

If you have been around for a while, you may also know about the existence of launchers which are named as launcher.swf and placed in System/Flash UI/. However, you may not know what they do precisely and I'll try to explain that in this post.