:::: MENU ::::
Posts tagged with: as3

AS3 Regular Expression Global Flag

I’ve been playing around with using Regular Expressions in AS3 using the RegExp class, and recently ran into an issue where only a single result was being returned when running my regex against a string that should have contained multiple results.

To give a bit more detail, I was trying to parse all of the tags out of an HTML document. I went about doing this by using the match() method of the String class, which returns an Array containing all the matches found in the given String. The basic code was as follows:

As noted in my comment, this would always return an Array containing only one result (even though I could see multiple matches in the string).

The Solution:
The reason my search was only returning a single result was that I did not include the global flag in my RegExp. The reason I did include it is that I had never heard of it. For those of you that have also not heard of it: “When the g (global) flag is not included, a regular expression matches no more than one match.” Luckily, its’ implementation is quite simple. All you need to do is include “g” at the end of your expression.

So to update my original code to include all matches:

There are also some additional flags that you can include in your Regular Expressions, you can read about them all here: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea7.html


AS3 – Removing Elements While Iterating Over an Array

I recently ran into an issue where I had a foreach loop iterating over an ArrayCollection of objects. Inside the loop, I was doing a simple check to see if the current object contained a matching property, if it did, I then removed it from the collection. I soon realized that the number of elements being removed didn’t quite match up to what I would have expected. The cause was quite simple: When removing items from a collection, you update the length of that collection, which in-turn breaks your iteration. This seemed like a very common problem (which I found to be true after a bit of googling), and luckily there are a number of ways to solve this. The very simple solution which I ended up implementing is as follows:

The Solution:
Instead of using a foreach loop, I switched to using a for loop. I then iterate over the collection backwards so that any updates to its’ length have no effect on the iteration.

That’s all there is to it. It’s quite simply when you stop to think about it, but when banging out code at the speed of light, who has time to think.. ;-)


How to Enable SSH on the Chumby 8

“Secure Shell or SSH is a network protocol that allows data to be exchanged using a secure channel between two networked devices.” (Secure Shell – Wikipedia, the free encyclopedia ).

What does this mean, and why should it matter to a Chumby developer? To put it simply, SSH allows us to easily connect to the Chumby device through the command line. In turn, this let’s us force the Chumby to do our bidding (insert evil laugh here). What might you want to tell your Chumby device to do? Well, for starters, you might want to tell it to run your application. This is by far the fastest and easiest way to test and debug your Chumby apps. If you’d like to learn more about creating and testing Chumby apps, you can read my full blog post on the topic HERE! But first, make sure you read through this tutorial and get SSH enabled on your Chumby!

Before you can enable SSH, you will first need to unlock the mysteries of the hidden Geek Menu. If you are unfamiliar with how to access the Geek Menu, I recommend that you read my blog post “Accessing the Geek Menu on Your Chumby Device” before continuing. If you’re already skilled in the arts of Chumby geekery, then feel free to move to the next step!


Once you’ve made your way into the Geek Menu, enabling SSH is a simple matter of clicking the button labeled “SSHD.” You should see a small Chumby logo appear next to the button, then quickly disappear. SSH is now enabled on your chumby device!

It’s important to note that SSH will only stay enabled until you reboot your Chumby. If you shut down your device, then start it up again, you will need to go through these steps again to re-enable SSH.

If you’re lazy like me, and don’t want to have to go through the process of enabling SSH each time you restart your device, you can SSH into your Chumby and enter the following command:

Once this command has been entered, SSHD will be enabled on your Chumby device by default! You can find more info. on this as well ass other cool tips and tricks at you can do with SSH at: Chumby tricks – ChumbyWiki

That’s all there is to it! Now that you have SSH enabled, why not check out my post on “Connecting to a Chumby Device Over SSH.”

Related Posts:



How Robotlegs Keeps me Relaxed with the RelaxedEventMap

While implementing the Robotlegs framework into my first application, I came across a rather common issue: How do I properly manage my views? To give you the basic run-down, my application has a number of different views (menus and various other screens) that need to be shown on the display at different times throughout the application lifecycle. What I wanted was a way to store all of my views, and be able to map events to show a specific view at a given time (ex: a user clicks the logout button in some component, I want the login menu to be shown). Add to this situation the fact dependency injection (while wonderful) has one pretty major flaw: If the object that needs to listen for a particular event is created after the event is dispatched, you end up with a race condition, and the object usually loses (and as such could be shown in an invalid state). For the example of the login menu, let’s say that the use clicks the logout button, the event is fired to trigger a logout command, which then tells the application to display the login menu. This is all well and good unless there is some event that the login menu needs to listen for that gets fired before it is created (ex: The logout Command fires an event to tell the app that the user has logged out and this event contains a message “The users has been logged out successfully” that the login menu is supposed to display). If you’re still managing to follow my confusing-ass example, give yourself a high five!

THE SOLUTION: Continue Reading


Mastering property existence with the hasOwnProperty method

For a long time I’ve struggled with determining whether or not a property exists in Actionscript 3.0. Like many people, I would often find myself writing somewhat tediously repetitive conditional checks such as:

Other than the fact that this is a lot of code to write (especially when you have a long conditional that checks 10 or 15 properties), this would work “most” of the time. I say most, because if the property you were trying to validate didn’t exist at all (i.e. there is no property name “myProperty” in your object), then you would get a nice “null object reference” error.
Continue Reading