Flash Debug Class - dPanel
While the Alert Class can be good for debugging applications, during development of a couple of personal projects I’ve seen the need to create another class which allows me to monitor variables which are likely to change constantly. One such variable is the current frame rate. Using the Alert or trace actions to monitor values that change as much as the frame rate is impractical, especially when you want to also monitor several other variables in real time. For this reason I’ve created the dPanel class.
An example of the dPanel is shown below. To show the dPanel you need to press the ‘transition key’, which for this example has been set to theĀ grave accent key (this key is typically underneath the ‘Esc’ key on Windows keyboards and to the left of the ‘Z’ key on Mac keyboards). Pressing this will slide the dPanel into view. Press the grave accent key again to slide the dPanel out of view.
There are three functions publically available:
init() - you call this method once to initialize the class with your desired settings
addSection() - adds a new section to the dPanel
update() - updates the specified section
Simple Usage
Using the dPanel is very easy.
- All you have to set things up is make a call to dPanel.init(), passing to it a reference to the stage.
- You then call dPanel.addSection() passing to it a name for the new section and if desired, the colour of the text shown in that section.
- When you want to update that section, you simply call dPanel.update(), passing to it the name of the section you want to update and the value you want to update it to.
Here is example code which uses the dPanel to constantly show the mouse position:
import com.dVyper.utils.dPanel; import flash.events.Event; // INITIALIZE dPanel dPanel.init(stage); // ADD A NEW SECTION dPanel.addSection("mousePosition"); // UPDATE THE dPanel EVERY FRAME TO DISPLAY MOUSE COORDINATES stage.addEventListener(Event.ENTER_FRAME, updateDebugPanel); function updateDebugPanel(event:Event):void { dPanel.update("mousePosition", "x:"+stage.mouseX+" y:"+stage.mouseY); } |
And that is all there is to it! The dPanel is very easy to setup and use and I’m sure will prove very useful to you!
Click here to continue reading
‘with’ Statement Performance
Whilst reading a post from the Learning ActionScript 3.0 blog I noticed a tip which dealt with use of the ‘with’ statement. This reminded me of a post which I published on the old version of this site.
The ‘with’ statement can be used in your code to help make the code easier to read. Examples of how useful it can be can be found in the documentation.
I’ve never actually used the ‘with’ statement in any of my personal projects however after reading an article which mentioned it I decided to see whether or not there was a speed increase to be gained from using the ‘with’ statement. I created a small test which attempts to determine this which you can try out below.
How to use the test is self explanatory. When you start a test, 500 MovieClips are created. On every frame, the position, dimensions, alpha and rotation of each MovieClip is altered to a random value. You can view how long it takes for each frame to render in the dPanel by pressing the grave accent key (the ‘dPanel’ is a class I have created for debug purposes - I will make it available in the near future).
I presumed that the ‘with’ statement would be faster because there are less reference calls but you can see for yourself that the ‘with’ statement is actually a little slower.
Flash Alert Dialog Class
I actually built an Alert class a long time ago and have used it very frequently for my own personal use. I recently received some impetus to update it after finding out that one person actually copied my class and then passed it off as their own on the flashgods forum (It’s now been taken down).
And so I’ve now updated my Flash Alert Dialog class, a class which enables you to display a modal dialog message box with AS3 very much like the built in Alert for Flex. Here is an example showing how the Alert can be used: Click here to continue reading