Sunday, March 18, 2012

Flash Font Embedding

I recently ran into a problem involving embedding a stylized font (Bold, Italic, etc) in a dynamic text field. As soon as I changed the content of the text field, the font would lose its style and revert to its Regular version. After a lot of messing around with embed settings, I finally discovered that the problem involved Anti-aliasing and that this would occur with any textfields that were set to be anti-aliased for readability.

Setting the textfield to Bitmap anti-aliasing resolved the problem but left the font looking a bit gritty. The best solution seems to be to set the field to Custom anti-aliasing. Lo and behold, the content of a textfield with custom anti-aliasing can change without killing the style of the font.

Tuesday, November 15, 2011

Stupid "Flash Player Not Found" Error

When installing a fresh copy of Flash Builder 4 in Windows 7 and trying to debug a project without an HTML wrapper I often get the error "Flash Player not found". After much searching, I have finally found the ridiculous solution. First of all, you must download a debug version of Flash Player and associate .swf files with it either through the Windows control panel or by right clicking and choosing Open With...

Simple enough, but this alone will not fix the error. Here's the ridiculous part of the process. You need to right-click the debug Flash Player that you downloaded and run it as an administrator. Doing this a single time should cause subsequent runs in Flash Builder to proceed without a hitch. So dumb.

Friday, July 1, 2011

Facebook And Caching

I've been doing a lot of Facebook/Flash game integration as of late and I recently ran into an incredibly annoying caching bug. Basically the integration works like this:

1) a "share" button in the game makes a call to Facebook's sharer.php script with a parameter pointing to a PHP file
2) this PHP file reads an XML file (specified via URL parameters) that contains the information that should appear in the Facebook post (link, title, picture URL, etc)
3) the PHP file uses this XML info to generate an HTML page with the appropriate metadata
4) Facebook's sharer.php script reads this HTML page to generate the Facebook post

Now, here's the problem. Facebook was caching an old version of the PHP file. As a result, I would try editing the XML to change, say, the title of the Facebook post, and my changes would fail to appear. Very troublesome.

The fix is quite simple. Facebook's sharer.php script works by passing in a 'u' parameter that holds the URI-encoded URL from which to generate the post. Here's an example pointing to Google:

http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fgoogle.com

Facebook appears to cache the page that is specified in the 'u' parameter, so in order to force it to read a fresh version of the page, you can append a dummy parameter to the end of the URL. So instead of pointing it to http://www.google.com, I would instead point it to:

http://www.google.com?v=1

which would appear in the sharer script with URI-encoding as:

http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fgoogle.com%3Fv%3D2

So in the Flash game, I generate a random number every time the share button is clicked and make a request to the sharer.php script with that random number tacked onto the end of the URL in the 'u' parameter. Take THAT Facebook.

Sunday, January 30, 2011

String To Enum Conversion In C#

In the XNA project I'm currently working on, many of the animations have a state for each cardinal direction. This information is stored in XML as a string (NE/NW/SE/SW). However, in the code it's convenient to store this information as an Enum like so:


public enum Facing {
    NE, SE, SW, NW
}

In order to determine which state of the animation to use, it becomes necessary to convert between the Enum and the string in the XML file. Fortunately, there's a handy function Enum.Parse that makes this really easy:

Facing enumValue = Enum.Parse(typeof(Facing), directionString);

Very handy. I haven't really used enums before but they're becoming a very useful tool.

Sunday, December 19, 2010

Explicit Casting vs. Using the "as" Keyword

There are (at least) two ways to cast an object in C# and I recently became curious about the difference. Apparently, if an explicit cast fails it will throw an InvalidCastException. Alternatively, if a cast that uses the "as" keyword fails, the target object will be given a null value.

So using the "as" keyword is perhaps slightly riskier since the program will continue on its merry way when there's a failed cast until you try to use your object and find out that it's null. However, I suspect most of the time this won't matter because the object is likely being casted for immediate use. So if for some reason you want your casts to be able to produce a null value upon failure, the "as" keyword is the way to go. Other than that, it seems like the difference will not have severe implications.

Wednesday, December 1, 2010

Flash Builder 4 "Java heap space" error

While attempting to compile and run a Flash Builder 4 project recently, I was receiving an error titled "Java heap space" with no additional information given. Some searching revealed that the IDE was running out of memory and a configuration file needed to be tweaked to give it more. Several forum posts suggested altering the jvm.config file in the /bin directory for the appropriate SDK such that the line:

java.args=-Xmx384m

has a higher numerical value. From what I understand, this is an argument passed in when opening the IDE that specifies an upper limit on the memory that the Java compiler is allowed to use. Unfortunately, changing this line did not fix the error. After some more searching, I found a forum post from an Adobe employee that suggested changing the eclipse.ini file in my Eclipse install directory so that the line:

-Xmx384m

has a higher value. I bumped this up to 768 and the error vanished. This is the same argument as the one in the jvm.config file but I suspect that the jvm.config argument was being ignored in favor of the eclipse.ini one. I do recall choosing to install Flash Builder 4 as a plug-in to Eclipse rather than a stand-alone application, so that may be the reason it's favoring eclipse.ini.

Sunday, November 21, 2010

System.out.println("Hello World");

A blog at last! In this digital brain-dump I plan to share my findings and perhaps create a few lessons about things that interest and inspire me, in hopes that they will do the same for someone else! I have taken so much from the collective knowledge of the internet community over the past few years and this is my first step to giving some of it back. I am a computer scientist by training and a software engineer by trade. I make video games now (for fun and for profit) and love ever minute of it. I plan to post about various programming topics as I learn them for myself, as well as any useful tips and tricks I pick up along the way. Right now I'm working in Flash/AS3 for my job and XNA/Python on a hobby project. Plenty to learn there!

In any case, my dream is for this blog to grow and be full of useful information for fellow disciples of the digital domain. I'm looking forward to seeing what this baby can do!