Nov 17

Flash Debugger Tutorial – How to Debug Adobe Flash

Thu, 11/17/2011 - 22:02 — julie

When you start programming in ActionScript 3.0, in the beginning you are very likely to get stuck in programming mistakes. You have to have a lot of practice to write bug free ActionScript 3.0 .Even when you are a professional developer you are still prone to getting stuck while coding. Flash has a very reliable debugger built into it which comes in handy a lot of times. In this tutorial I am going to show you how to use the Flash debugger to debug your code.

This is an advanced Flash tutorial. If you don’t yet know how to create a free Flash website, you should check out my Flash tutorial before reading this tutorial.

First of all let’s write some lines of code to be used by the debugger.

var s:Number;

s = sum(3.5,5);


function sum(i:Number , j:Number):Number{

                var sum:int = i+j;

                return sum;


If you know ActionScript 3.0 then you will easily understand the above code. Its contains a function sum which adds the two numbers it takes as its parameters and returns their sum. The actionscript code is using this function to add 3.5 and 5 and store the returned value in the variable s.  There is also a bug in this code. When I run the program, I should be seeing the value “8.5” in my output window, but I am seeing only “8”.

You might have noticed the problem in the code but we are going to find the problem out with the help of the Flash debugger now. To run the debugger, the first thing we need to do is to insert break points in our code. You see the flash debugger lets us execute our code one line at a time. But for that it needs an initial breakpoint. A break point is the position where the automatic code execution stops and the manual line-by-line code execution comes into play. To insert a break point in the code, move your cursor to the line where you want to insert the breakpoint and press “CTRl+B”. You will see a red dot along that line indicating a breakpoint. I have inserted a break point in the line where the function is being called.

Now we are ready to start the debugging. Press the keyboard shortcut CTRL+SHIFT+ENTER to start the debugger. Once you press the keys, your whole screen would be changed.

In your code you will see a yellow colored arrow which indicated the current position of the execution, in the bottom left column you will see a list of all the variables along with their values. In the top left panel you will see buttons which control the execution of the code.

Right now the program control is on line number 3. I press the step into button to move the control inside the function.

You can see the yellow arrow move to sum function and you will also see the variables i,j,sum and their values.

I could have avoided entering the sum function by pressing the step over button when the control was on the line with the function call. I can also press the step out button any time to step out of the sum function and proceed with the rest of the code.

But right now let’s keep executing the rest of the lines in the sum function. Press the step in button to execute each line of code. You will see that the variables become updated on each step. When I have executed line 8 of the program, I see that the variable sum has a value of “8”.

The value of sum should be 8.5 here but it is 8. This indicates that the error must be at this place in the code. Indeed if we look carefully, we can see that the type of the variable “sum” is declared as int. Since int cannot store fractions that is the reason that we have been seeing 8 in the output instead of 8.5 .If we change the type of sum to Number and then execute our code again, we can see the correct value of 8.5.

And so we have successfully used the debugger to debug our code. This is a very small code and the bug could be spotted without the help debugger too, but when you are managing large and complex codes then debugger will definitely be of huge help and it will help you see the bugs in the code which cannot be spotted very easily without it.

Do you want bug-free code? Use Wix, an amazing free Flash website builder that will let you create a very professional Flash website in the fraction of the time it takes creating it from scratch.

Copyright 2009. E-mail Me
Auto Spare Parts