:::: MENU ::::
Browsing posts in: Code

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.. ;-)


FlashBuilder 4.6 Broken Workspace FIX

I’ve been running into a plaguing issue lately with FlashBuilder 4.6, and that is that every few days/weeks/other random increment of time, my workspace will become corrupt, and I will no longer be able to open it. The signifier (for me) of a corrupt workspace is generally that FlashBuilder freezes while I am in the middle of coding some (usually extremely important and time-sensitive update), then when I try to restart the application it hangs on the “Loading Workbench” portion of the startup sequence. Thankfully, I found THIS post written by Valentin Romonov which outlines a fix for the problem that doesn’t involve deleting the entire .metadata folder of the workspace (which then forces you to reset up all preferences, ties to version control systems, layouts, etc.).

The fix is quite simple: go into your project directory, and locate a file called .snap which is listed under the following path on Mac OSX: .metadata/.plugins/org.eclipse.core.resources Once you have deleted this file, simply restart FlashBuilder and you should be good to go! *Note that you will need to turn on hidden files in order to see the .metadata folder, instructions on how to do that can be found HERE.

A big thanks to Valentin Romonov for blogging about this fix, it has saved me a LOT of time and frustration!


Listening for events in a (Flex) Spark Itemrenderer

I recently ran into an issue where I was creating a custom itemrender in Flashbuilder (Flex) which contained a button. I wanted to listen for the button’s Click event and have an event handler within the itemrenderer respond to it. Sounds simple enough; however it did not work.. AT ALL! After a bit of fumbling around, and a whooooole lot of Googling, I found the problem AND (more importantly) the solution!

What was happening was this: When the button inside of my itemrenderer was clicked, the itemrenderer itself was receiving the click event first, and after notifying the parent list that it had been clicked, some updating took place in the list and all further events were killed (including my button’s click event). I’m sure there are way more technical ways to explain exactly what was occurring; however, I’m lazy, and I have a rather simple fix which works just fine for my purposes, so I’ll spare you the tech jargon and smart talk for now..

THE FIX:
Instead of listening for the buttons MouseEvent.CLICK event, I instead listen for MouseEvent.MouseDown. That’s it (told you it was simple). Apparently, the MouseDown event is triggered before the click event (which actually makes quite a bit of sense), and as such, you are able to capture it before the itemrenderer swoops in and steals all the glory (and the events)!

THE GOTCHA:
It’s important to note, in the MouseDown event handler inside of your itemrenderer, you MUST call event.stopImmediatePropogation() on the event that gets passed into the handler method. Failing to do so will allow the event to bubble up the chain and once again give the itemrenderer a chance to steal the show. Calling event.stopImmediatePropogation() will stop the event dead in its’ tracks, and give you a chance to apply any logic you might have in your event handler (I’m assuming there is actually a reason you want to capture the event, other than making it your bitch..).

EXAMPLE ITEMRENDERER:


Getting Started With Robotlegs

I recently gave a presentation at the San Diego Flash Users Group (SDFUG) about getting started with the Robotlegs framework. Below are links to the source files for the example application (TweetBender) that I discussed, as well as some useful links for getting started with Robotlegs.



Creating Your First Chumby Widget – Part Three: Testing Your Application on the Chumby

In parts one and two of this series, we learned how to build an app for the Chumby, and how to connect to the Chumby via SSH. In part three, we will all of this knowledge to use and finally get our application running on the Chumby device!

Though there are a few methods for testing your application on your Chumby, I find the fastest and thus most useful way to be to tell the Chumby to load your application using SSH. To do this we will first need to setup a simple web server on your local computer so that the Chumby can find your application files. Ready? Let’s go!

Continue Reading


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 to Update Your Chumby’s Firmware

In this tutorial I’ll walk you through the process of updating the firmware for the Insignia Infocast 8″ and the Chumby 8 (both follow the same steps). You might be wondering why you would want to update your firmware. The main reason is that the latest firmware contains updates to support Actionscript 3.0. So if you’re looking to do any AS3 development for the Chumby, you will need one of the devices listed in this tutorial with the latest firmware installed on it (note: there will be additional devices released in the future that also support AS3).

If you have an older Chumby device, the process for updating the firmware is still the same.

Continue Reading


How to enable SSH on the 8″ Insignia Infocast (Chumby)

“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 the Insignia Infocast 8″” 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:



Getting Screenshots From Your Chumby Device

As I was going through the process of writing my tutorials for the Chumby devices, I found myself wanting to get screenshots from the device to help better illustrate the various menus and screens that I was describing. Luckily for me, Chumby was one step ahead of me on this! On the Chumby there is a hidden menu, lovingly referred to as the “Geek Menu”, that gives you the ability to enable some extra features. One of these features, called “FBCGI” (short for Frame Buffer to CGI), copies the latest image from the frame buffer (i.e. whats currently displayed on the screen) to the cgi-bin directory on the device. You can then access these image files (screenshots) through your browser. The process for enabling FBCGI and accessing the screenshots is outlined below:

Enabling FBCGI
The first step to enabling FBCGI is to access the hidden “Geek Menu.” If you don’t know how to do this, you will want to read my tutorial “Accessing the Geek Menu on Your Chumby Device” before continuing.

I will be demonstrating how to accomplish this using the Chumby 8; however, it should be a very similar process on any other Chumby device.


To enable FBCGI, simply click on the FBCGI button (logical, right?)

Accessing the Screenshots
Now that you have FBCGI enabled, you will be able to access images of whatever is currently beingdisplayed on your device’s screen. How you access these images will depend on whether you are currently in the control panel, or viewing an app. The reason for this is that there is a separate frame buffer for each of these views. Frame buffer 0 (fb0) holds images of your widgets, while frame buffer 1 (fb1) holds images of the control panel.

To access screenshots of the control panel:
Open up a browser and go to the following url: your.devices.ip.address/cgi-bin/custom/fb1

To access screenshots of your widgets:
Open up a browser and go to the following url: your.devices.ip.address/cgi-bin/custom/fb0

That’s all there is to it! Now you can take screenshots of all the great apps you develop for the Chumby to show off in your portfolio!

Next Steps:
Check out some of my other Chumby related tutorials!



Pages:1234