Implementing a QR Code Reader as Firefox Extension Part 3

Hi there, once again it’s about time for an update on my work with the Firefox QR Code Reader Plugin. I did some research on how the syntax of actionscript3 looks like and with that information I started with the adaptation for my own QR Code Reader.

After some implementation and testing, I successfully implemented the feature for starting Firefox with a decoded http link! The user can scan a http link and gets the option to start that link directly in the browser.

First I created a new actionscript3 file which I named Then I took the sample QR Code Reader of the library and picked out the things I needed. Because I was already  familiar with the framework, I rewrote the “ResultView”, which shows the decoded and parsed result of the QR Code. Then, I had to parse the data first, in order to identify what to do next. So I wrote this new method:

private function identifyData(data:String):String {
var result:String = "empty";
if (data != "") {
btnSpriteOpen.visible = true;
btnTextData.visible = true;
var array:Array = data.split(":");
if (array[0] == "http") {
result = data;
} else {
btnSpriteOpen.visible = false;
btnTextData.visible = false;
return result;

Here I splitted the incoming data on “:”, to determine if the head element of the array equals “http”. When it does, the method returns the whole link, which is set to a local variable that is visible in the whole class. That variable is finally used by a mouse-event listener, which starts the browser:

private function startBrowser(e: MouseEvent):void {
if (encodedData != "") {
var url:URLRequest = new URLRequest(encodedData);
navigateToURL(url, "_blank");
} else {
trace("encoded data is null");

This function starts only , when the user clicks on the specific mouse-event, which only occurs if a link is parsed. The trace() method which you can see here is only for debugging. It simply writes a message to the output, so it is easier to see if something went wrong.

The last method I needed was to show a correct message after decoding a link. Therefore I wrote this part:

private function getString(data:String):String {
var result:String = "";
if (data != "") {
var array:Array = data.split(":");
if (array[0] == "http") {
result = "Do you want to open that http link?";
return result;

Finally I used these methods. This is the last part I added, which starts, right after the decoding of the QR Codes took place:

var returnData:String = identifyData(;
if (returnData != "empty") {
btnTextOpen.autoSize = TextFieldAutoSize.LEFT;
btnTextOpen.text = "YES";
btnTextOpen.selectable = false;
btnTextData.autoSize = TextFieldAutoSize.LEFT;
btnTextData.text = getString(returnData);
btnTextData.selectable = false;

btnSpriteOpen.addChild(btnTextOpen);;, [0xEEEEEE,0xCCCCCC], [0.9, 0.9], [0, 255], new Matrix(0, 0.01, -0.01, 0, 0, 10));, 0, 80, 20, 8);
btnTextOpen.x = 0.5 * (btnSpriteOpen.width - btnTextOpen.width);
btnTextOpen.y = 0.5 * (btnSpriteOpen.height - btnTextOpen.height);
btnSpriteOpen.x = 0.5 * ( 280 - 200 );
btnSpriteOpen.y = 240;
btnSpriteOpen.buttonMode = true;
btnSpriteOpen.mouseChildren = false;
btnSpriteOpen.addEventListener(MouseEvent.CLICK, startBrowser);
encodedData = returnData;

This will parse the data, and create a text field with the correct text and a button to open the link, which is listening on a mouse event.

After some tests everything runs as planned: a decoded link can be opened with a button in actionscript3.

I have to admit, that the positioning of the button was quite an agony. At first the text and the button did not show up in the  place I wanted them to be  for a long time (I placed them relative to the object which enwraps them, but they just showed up in random spots) until I restarted flashdevelop. Then it worked fine, just how I wanted it.
Next update will follow next week!

, , , , ,
  • Delicious
  • Facebook
  • Digg
  • Reddit
  • StumbleUpon
  • Twitter

One Comment

  • Andy Lynn says:

    Great article! It is very exciting how fast QR codes are now growing in the US. Check out the QR codes we are creating here at Scanlutions ( Thanks for creating awareness!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>