Archive for the 'Silly' Category

How Pixel Perfectness Drove Me Mad

I’m always overly obsessed when it comes to placement of text in Flash IDE. If the font is a pixel font, and it does not lie exactly on whole numbers in the x and y axis, then the font will appear blurred. From this habit that I had in handling pixel fonts, it soon spread to all objects that I had on the stage; I would want *everything* to be lying perfectly on whole numbers in both axis.

As you might have guessed, this pixel perfect habit of mine drove me rather mad whenever the rest of the team did not bother about it. I could easily spend hours just perfecting the coordinates. Yes, it’s highly possible more of a disease than a habit. *loL~*

Anyway, as I was playing around Flash IDE today, I found the cure! Snap to Pixels! Why haven’t I explored this in all my years with Flash?! :(

So if you are suffering from pixelperfectitis as well, here’s your medication.

View -> Snapping -> Snap to Pixels
Snap to Pixels

Ahh… How nice to find a cure… :D

AddThis Social Bookmark Button

Loading Text From XML

Made a silly mistake while loading text from an external XML file and I really really don’t want anybody to follow in my footsteps. :P

<strings>
    <string id="someString">
        <![CDATA[Sentence one\nSentence two]]>
    </string>
</strings>

Does the above code looks flawed to you? Take a moment and look it through. :)


When you do the below AS2 codes in flash, what the \n does in the string is basically creating a newline, and thus "Sentence two" will appear below "Sentence one".

var txt:TextField = createTextField( "txt", _root.getNextHighestDepth(), 100, 100, 200, 200 );
 
txt.text = "Sentence one\nSentence two";

Happily, I ported all these original strings into an XML and got it loaded. What puzzled me was that, when these text were actually loaded, the \n didn’t work! The textfield simply displayed "Sentence one\nSentence two" without the newline. I sought help from a fellow colleague, Arul, and together, we still could not see what’s wrong with it. We left office without solving that "bug".

That night, Arul called to say, "Hey, with CDATA, we don’t need the \n! We simply just need to hit <enter>!" Immediately it struck me, oh ya! That’s the whole idea of using CDATA isn’t it? We got too engrossed with the wrong problem! :D

The next day, I changed all the \n to <enter> key, and expected things to work. Unfortunately though, the text did not turn out as expected. Flash had interpreted my <enter> in XML as double <enter>s when it’s being displayed on the textfield!

I sought Arul’s advice again and this is what I got. Flash interprets <enter> in external text sources as "\r\n", which explains the double <enter>s being rendered. So, what I actually had to do is to run through the string, strips off the "\r", and change it to "" (empty string).

Here’s the code that solves the above issue.

function processString ( s:String ):String
{
    return s.split("\r").join("");
}

Hope this helps! ;)

AddThis Social Bookmark Button