Why doesn’t System.Capabilities class have browser property?

Posted on October 17th, 2008 in Actionscript 3.0 | 1 Comment »

Can someone explain why Adobe put in the feature:


trace(Capabilities.os); // gets the operating system

and not something like


trace(Capabilities.browser); // gets the browser... this property doesn't exist unfortunately...

 

On a game project I’m working on, the game uses key combinations such as CTRL+Z and CTRL+Y for certain features. Unfortunately, combo keys using CTRL key don’t work in Internet Explorer (but they do work in other browsers). What I want to do is detect if the user has IE, then change the key combinations to SHIFT+Z and SHIFT+Y. The only way to determine the browser is by using a server side language or Javascript to pass in the browser into Flash… grr….

Does anyone know if there’s a way to use ExternalInterface to send the keys? I don’t want to depend on Javascript being on a page or specific Flash vars be sent to the user… but I may have to do so.

Update 10/17/08:

I found a way to detect for IE.

Capabilities.playerType; //Returns ActiveX if in IE.

A string that indicates the type of player. This property can have one of the following values:

  • "StandAlone" for the Flash StandAlone Player
  • "External" for the Flash Player version used by the external player, or test movie mode..
  • "PlugIn" for the Flash Player browser plug-in
  • "ActiveX" for the Flash Player ActiveX Control used by Microsoft Internet Explorer

AS3 EventManager 1.23: cleanUp method added

Posted on October 11th, 2008 in Actionscript 3.0 | 2 Comments »

A major reason why some users of my EventManager class may see more memory leaks being shown than actual memory leaks is because EventManager stores all the listeners in a dictionary. If we remove a display object then technically (if weakReference is set to true) the listeners are removed for the DisplayObject and its children. Until today, EventManager required coders to manually remove every listener they created with EventManager even if Adobe’s GC actually removed them.

As much as I like the listeners being auto removed, I feel it’s better in practice to manually remove them so you know what’s going on while you code. If you always depend on that to happen then you might find yourself with memory leaks.

I never thought to actually have EventManager check each object to see if it’ll trigger the Event EventManager says it has. Therefore, I added cleanUp which will go through all of the listeners and remove the ones that don’t trigger anymore. This new method means that the EventManager should be more accurate in what’s going on (especially if you call a deepTrace now). It won’t work all the time of course (multiple listeners in one object will still be reported as a leak unless garbage collection takes care of it or you use EventDispatcher’s removeEventListener to remove them).

Anyway, check it out.

Boomshine Flash Game ported to IPhone

Posted on October 7th, 2008 in iphone | 10 Comments »

Boomshine, my most popular Flash game, has just been released on the Apple ITunes store. You can now download it now on the IPhone or IPod touch.

Jacob Thurman , whose blog current theme is coincidently the same as mine (makes things a bit confusing), is a developer in Chicago who contacted me recently with a prototype. I worked with him to get the game to match the web version as close as possible, and I think he’s done a great job.

As a game designer, I can’t express in words the feeling I get that people will be playing Boomshine on the subway or on the street. It’s funny that the harder I work for opportunities the more they come to me.

Anyway, click here for the download link (will auto-open in ITunes, or if you’re viewing this on your IPhone it’ll launch directly on your IPhone’s store). New features are planned for future versions (global highscores, game modes, etc).

Boomshine will hopefully be the first of many of my game designs to be ported to IPhone.

EventManager Class Update

Posted on September 30th, 2008 in Actionscript 3.0 | 3 Comments »

Hate keeping track of event listeners?

Wish you had removeAllListeners()?  Wish you had removeAllListeners(EventDispatcherWithABunchOfListeners)? Wish you could remove all listeners that targetted a specific function?

A while ago I posted a class I wrote to handle actionscript 3 listeners.

I updated EventManager.as today to by default set weakReference to true and to always add the listener (if you used it before it might break code that didn’t declare the last parameter).

The class has come in handy in so many projects and makes code much nicer. It’s especially useful for destroying all the listeners of an external SWF…

Find the latest version here.

Note that the class doesn’t have full support for listeners with useCapture specified… but who really uses those anyway?

AS3 Primitives

Posted on September 17th, 2008 in Actionscript 3.0, OOP | 6 Comments »

*Edit: I have found that I am wrong about the following (as shown from the comments). In AS3, numbers are in fact placed in their wrapper classes. My interpretation are wrong. You can keep read the following if you want to know how it DOESN’T work. Basically what I describe is how Java works. AVM2 doesn’t do this, it wraps everything as an object… Sort of strange as there are performence gains using primitives.

I read a post recently that asked whether AS3 Number objects are actually treated as objects in AS3.

Number, int, etc are primitives. Just like in Java, these types have their Object class associations in case you want to create instances and call various methods that come with the Number class. For example, the Number class has functions like toFixed for number precison and accuracy.

The concept of primitives are sort of confusing to newer programming as they go against object oriented programming. In fact, in Smalltalk, one of the first OOP languages, EVERYTHING is an object. The +, -, *, etc are treated as “messages”.

In Smalltalk, since everything is an object and has messages passed, you have to specify the function for “+” and “-”. Primitives in higher level languages don’t have that just for this reason. You don’t want to have to write the code to add two numbers together do you? The concatanation syntax for Strings is also “+”. Notice how “-” is not properly handled with Strings while it is with Numbers… 

Also, in terms of an ideological argument, Number can be said to be the lowest form to describe an object. Think of the composition property of object oriented design. Everything is made of objects that are made of objects that are made of objects… There are theoretically an infinite amount of layers in-between.  Object oriented design is the practice of selecting certain layers and abstracting the rest. But at the very core, every object has to be made up of primatives (more specifically, since Strings can be represented as numbers). Think of any class you’ve ever programmed. The properties will always have either primatives or other objects. If you recurisvely loop through other objects they will all also be made up of primatives (unless they have no properties at all… that’s sort of an anomoly and bad programming design dependant on “isA” relationships… so I’m going to avoid that tangent).

Primitive types are the building blocks. Just like materials are made from atoms… you can’t really go lower than Numbers in describing an object. Additionally, primitives are passed by VALUE rather by reference.

Here’s another post I wrote a while back that went a little deeper into this concept.

Google Chrome Doesn’t Always Seperate Each Tab to Different Threads

Posted on September 3rd, 2008 in Other, Technology | No Comments »

I’m using Google Chrome right now, and I have to say that it’s blazing fast. Based on Javascript benchmarks I’ve ran from around the web, I found it to be way faster than IE7, way faster than Firefox 2, much faster than Firefox 3, and even faster than Opera. Chrome’s new Javascript engine is awesome, but I just wanted to clarify that tabs do not always run as a seperate process.

Google mentions on their in one of their Chrome FAQs that it’s up to the web developer to decide if a new link opens as a seperate process or not.

I found this out first hand by going to W3 School’s html samples page and clicking on one of the links. Instead of opening on the same tab, the link opens on a new tab. So now I had http://www.w3schools.com/HTML/tryit.asp?filename=tryhtml_basic open in a tab. I edited the html source code on the left frame and put in a simple infinite loop with Javascript then hit run. As expected, the tab, instead of the entire browser, hung.

However, when I clicked on the W3 School’s html sample tab (which launched the now frozen tab), I noticed it was also frozen. My other tabs, such as Gmail, Google Calendar, etc were fine.

Google answered why: 

New tabs spawned from a web page, however, are usually opened in the same process, so that the original page can access the new tab using JavaScript.

Makes sense. In fact, that is one of the reasons why current web browsers run in a single thread. No big deal. Most of the time I have multiple “sessions” of browsing and I don’t mind if a few tabs share the same process thread.

Anyway, if you don’t have Google Chrome, get it. Finally multi-core machines will see benefits in browsing the web. I can have 10 tabs open without seeing a slowdown.

Web Standards

Posted on August 15th, 2008 in Other | 1 Comment »

As many Flash Developers have heard, ECMAScript 4 has died. I’m not going to go into the details of the decision, although you can most likely blame Microsoft and their 80% browser stronghold on the web.

Nevertheless, the decision has raised significant issues around the web regarding web standards, and whether or not they have worked in the past or not.

Take for example IE and Firefox. Every web developer has experienced the browser compatibility problem. 90% of forum posts start with “Strange CSS bug, works in IE but not in FF” or “Script works in FF but not in IE” etc. Ironically, Adobe Flash’s success has largely come from this problem as Flash runs ubiquitously on every browser. While the W3C has made progress on creating web standards, in general it’s been a failure. Even newer browsers, aware of the recommended standards while in development still don’t pass Acid2. But why has this failed?

I think it’s by choice. Microsoft, Firefox, Safari, and Opera fight for the larger share in browser usage. If coders create a site that fits their browser, the idea is that more users will download that browser. For a long time, IE was the standard. Whenever a site didn’t work in IE, as a developer, you MADE it work on there knowing that 90% of the visitors to your site would have IE.

But a phenomenon happened: the open source movement. Firefox arrived as an open source competitor. It’s not that Firefox was better than competitors (it wasn’t). But because of the nature of Firefox just being open source, the browser had more power than other competitors to browser dominating Internet Explorer. Firefox complies with the web rather than the web complies with Firefox. This development strategy could have only existed on an open source project, as the developers of the project did not have the authority or mindset to take over the web.

But as mentioned earlier, Firefox has led to major problems to web designers and coders. It’s a pain to create stuff! Everyone wants a page to look the same on every browser and on every computer. Only a dream… and will stay a dream.

Having standards would fix this problem; however, how would the actual products react? How will innovation be affected? There are many parallels to government oversight in the economy and web standards… but we don’t have to go into that.

A fleet only goes as fast as its slowest ship. When Mozilla, Firefox, and Apple vote on a particular feature to be a standard, some will have to pick up the pace while others will have to slow down. And that is what has been happening at the W3C and ECMA. Adobe has included a bunch of features that it would have probably had to remove in order to comply with ECMA 4. Now that ECMA 4 is dead, Adobe can keep those features… and even develop new ones without having to wait for ECMA to accept or reject revisions.

Of course, the downside is that we developers will have to work extra hard to make our products work on multiple software. Meaning more browser specific pages and more time researching what works on a particular browser and what doesn’t.

But here is where I disagree. At this level, the benefit isn’t that someone with IE may see an awesome Javascript menu while someone on FF may see a image mapped navigation. The biggest misconception I have found is that coding standards are susceptible to the same criticism as software standards (Browsers, GUIs, colors). But it ain’t.

Here’s why: the standards proposed in ECMA 4 were in coding syntax rather than in any product output. At today’s high level coding languages, we can basically do anything we want with Javascript, Flex, and Actionscript; however, the syntax is different. And THIS is something that NEEDS standardization. Just because the experience of writing the literature of source code may be better and more intuitive on one platform than another doesn’t change the actual output of the product. This is why I think the dump of the ECMA standard is a BAD thing. The ECMA was a scripting standard. So Actionscript may get private constructors now, whooped-dee-do.

What would have happened if RSS standards weren’t introduced? Sure, maybe one RSS format would have “extra features”, but we wouldn’t have the RSS readers that we do today. The Google Reader team can focus on making their product better and not on how to read hundreds of different XML formats.

I’m not saying that ECMAScript is comparable to XML; however, I am trying to address the criticsm I have been reading trying to say that web standards hinder innovation and are always a bad thing.

The reason ECMA failed was because companies want to control the market. The excuse Microsoft and others use is that, in practical terms, the web doesn’t need certain coding features. But that’s just an excuse. Web applications are getting more and more advanced. A standard like ECMA 4, which would last for many years, needs to support the most advanced coding syntax as possible. Sure maybe most products are not big enough to really benefit from abstract classes, but in 2 or 3 years, when ECMA 4 was scheduled to be adopted and shipped with products, who knows? And what about in 5-6 years?

In other words, in the short term and for companies that have the capacity to advance their languages more than others (like Adobe) , and since AS4 may come out sooner, this decision is ultimately good in the short term and bad in the long term.

AS3 EventManager Class: removeAllListeners

Posted on July 2nd, 2008 in Actionscript 3.0, OOP | 8 Comments »

I heard about a class that Grant Skinner wrote called Janitor that was supposed to help keep track of listeners, but I couldn’t find it. Consequently, I wrote my own “EventManager” class for a gaming project I’m working on which keeps track of Event listeners in a project.

As all Actionscript 3 developers know, one of the biggest annoyances is keeping track of listeners and ensuring objects are collected in memory. This class does a lot of that for you, and even has a method removeAllListeners which has different filters. So let’s say some listener keeps calling a function, you can remove all listeners that point to that function. Or let’s say you want to remove ALL key listeners.

Here it is:

*EDIT 9/30/08: EventManager Updated. Click here to get it.

For example, let’s say you have something like so:


var obj:MovieClip = new MovieClip();
var obj2:MovieClip = new MovieClip();
obj.addEventListener(Event.ENTER_FRAME,Test,false,0,true);
obj = obj2;
obj.removeEventListener(Event.ENTER_FRAME,Test); // Does NOTHING!

Test will still be called every frame! Even though weak reference is set to true and there are no more references to obj! This is not good! But with EventManager…


var obj:MovieClip = new MovieClip();
var obj2:MovieClip = new MovieClip();
EventManager.addEventListener(obj,Event.ENTER_FRAME,Test,false,0,true,true); // last parameter actually adds the listener, see documentation in class of why this last parameter exists.
obj = obj2;
// Now we have a bunch of options, any of the bottom lines would work
EventManager.removeAllListeners(null,Event.ENTER_FRAME); // will remove all Event.ENTER_FRAME listeners
EventManager.removeAllListeners(null,Event.ENTER_FRAME, Test); // will remove all Event.ENTER_FRAME listeners that call Test
EventManager.removeAllListeners(null,null, Test); // will remove all listeners that call Test
EventManager.removeAllListeners(); // will remove all listeners

The only problem with the class is that this version does not distinguish useCapture events… But big deal. Maybe I’m naive, but how often does anyone actually set useCapture to true?

Anyway, if this class gets a lot of attention I’ll put it as open source on Google Code. Then someone else can add in functionality for useCapture.

This class was such a pain to code. AS3’s Dictionary is the only sure fire way to index objects as objects (as Array uses the result of toString() for indexes), but because (for some reason that’s beyond me), Adobe decided not to have a length property in Dictionary, my life was made very difficult. There might be some bugs, but based on my initial tests everything seems to be working fine. I wonder how Grant’s Janitor class is compared to mine. I really couldn’t figure out any other way to write the function definitions for EventManager.addEventListener and EventManager.removeEventListener (having actuallyAddListener and actuallyRemoveListener as the last parameter). I wish AS3 had a way to get the memory location value of an object. Something like Object.toMemoryString or something. That way Arrays could be used and the Object.toMemoryString value (which would be unique for every single object) could be used as keys.

If you decide to use this class, please let me know so I know my work hasn’t been in vain!

My Thoughts on Google and Yahoo Indexing Flash Content

Posted on July 1st, 2008 in Technology | No Comments »

Today Google reported that they’ve developed an algorithm to index Flash content (only text, not video or images). This news is clearly dominating Flash news sources around the web, with mostly mixed reviews.

Many bloggers are criticizing Google claiming that it’s impossible for any algorithm to figure out the text information of SWF files which load text from external sources (such as XML) because it’s impossible to know the format of the XML documents being transferred over. But who cares? I still don’t get why people are saying that that’s how the algorithm works. Google has stated that it’s able to crawl externally loaded SWFs (although they don’t couple it with the original SWF when indexing, which is a significant problem for sites that load multiple SWFs for navigation); consequently, they must be monitoring HTTP requests made by the SWF and can do the same with XML files. Google doesn’t need to know how the XML file is parsed… the Flash document will do that for them. They can just have the Flash load the XML file and monitor the text fields and see the value. That’s probably why they say, “To protect your material from being crawled, convert your text to images when possible”.

The only problem I see is if text fields are very dynamic. Maybe the algorithm only goes through static text fields? Because I see no way how a text field that displays random letters (for visual effect) being able to be indexed by any algorithm.

Here’s my prediction: Community tagging. Just like the Google Image Labler game, Google will ask users to tag/label Flash documents that their parser can’t index correctly. Humans would be the perfect computational tool to solve this kind of problem. Yes, there are millions of SWFs out there needing to be indexed, but we really just want the major ones parsed.

Firefox 3 Fixes Bug

Posted on May 30th, 2008 in Other, Technology | 1 Comment »

The keyboard bug with RC1 has been fixed for latest build (RC2)!

Phew!