Programming

Reducing .FLA File Size Using Save and Compact

I was working on a project to optimize the file size of a published .SWF file today. I wasn’t able to reduce the size of my file by that much, but at the same time I was removing assets from the Library of the source .FLA file. I noticed that after saving, the file size of the .FLA was not decreasing. I started to doubt my sanity, so I decided to see what Google had to say on the subject.

I found this helpful blog post on the subject.

Basically, when using Ctrl+S to save a file, the Flash IDE does a quick save. This quick save, doesn’t do anything to optimize the size of the .FLA file. However, if you use the File > Save and Compact command, Flash will compact the file for you.

However, be warned that saving in this way will remove the undo history for the file. So any changes you’ve made since you opened the file will not be recoverable.

Wednesday, November 11th, 2009 Programming No Comments

How to open a link in a new window using JavaScript…the right way.

First, the wrong way:

<a href="#" onclick="window.open('http://www.digitalmachina.com/');">the wrong way</a>

So what’s wrong with the above code?

  1. Since the href attribute contains a hash “#” character, and not an actual URL, search engines will not be able to follow the link. Search Engine Optimization (SEO) is extremely important, so this should be reason enough.
  2. If the user is not using a JavaScript enabled browser, the link will not work at all.
  3. Users will not be able to use any of the useful browser features available from the context menu for links including: Open Link in New Window/Tab, Bookmark This Link, Save Link As, Send Link or Copy Link Location. Breaking the functionality of a users browser is never a good thing.
  4. When the link is clicked on, the browser will append the hash character contained in the href attribute to the end of the URL in the address bar. This action by the browser screws up the user’s browsing history. Also, if the user feels like refreshing the page by hitting enter in the address bar, it won’t work. They’ll have to manually remove the hash character first.

Now, the right way:

<a href="http://www.digitalmachina.com/" onclick="window.open('http://www.digitalmachina.com/'); return false;" target="_blank">the right way</a>

What’s different?

  1. The href attribute contains the real URL of the linked page. This is SEO friendly, and doesn’t break any functionality of the user’s browser.
  2. The value of the onclick attribute ends with “return false;”. By adding this piece to the end of the string, it tells the browser not to follow the link contained in the href attribute. This is required now that the href actually contains a valid URL.
  3. Finally, if the user is not using a JavaScript enabled browser, the link will still work.

Tags: ,

Thursday, March 12th, 2009 Programming 2 Comments

ExternalInterface Error When Parameters Contain Special Characters

I ran into a problem today when using ExternalInterface in and ActionScript 3 project. The issue occurred in both Internet Explorer and Firefox. In the project, I was using ExternalInterface.call() to execute a JavaScript function, and passing a long text string as a parameter. The long text string happened to contain a bunch of new lines and slashes. In both browsers a JavaScript error was generated, and the error was not catch-able by a try…catch block in the Flash application. After some searching I found a blog post on Mike Chamber’s site about a known bug in the Flash plugin. The solution is to use String.replace() to sanitize the string before executing ExternalInterface.call().

stringParameter = stringParameter.replace(/\n/g, " ");
stringParameter = stringParameter.replace(/\r/g, " ");
stringParameter = stringParameter.replace(/\\/g, "\\\\");

Tags: , , ,

Wednesday, March 11th, 2009 Programming No Comments

MochiAds Releases Leaderboards

Mochi Mochi has released a new feature through their MochiAds service called “Leaderboards”. I’m still busy working on my next game, so I probably won’t integrate the new leaderboards into Cubical and Tetrical any time soon, but I eventually will. I’ll also be using them heavily in the new game. The leaderboards are very cool looking and at first glance appear to be very easy to create and use. Documentation can found here.

Tuesday, January 22nd, 2008 Programming Comments Off

Abstract Classes in ActionScript 3

For those of you that like the ability to create abstract classes, zeuslabs has written an interesting hack to mimic the behavior in ActionScript 3 (AS3).

Runtime Enforcement of Abstract Classes in AS3

Tags: , ,

Monday, January 14th, 2008 Programming Comments Off

How to integrate the Kongregate AS3 API into your game at runtime

Kongregate as finally released an AS3 version of their API. There are two methods to integrate the API with your game. The first method is to download a component and compile it into your game. The second method is to load the API at runtime.

As easy as it is to integrate with the Kongregate API through their component, I prefer to do as much as I can through ActionScript without using the Flash IDE. Also, if you are a game developer that posts your game to multiple portals with their own APIs, you may want to only include the API for each domain as needed.

› Continue reading

Tags: , , ,

Thursday, December 6th, 2007 Games, Programming 6 Comments