Archive for category Flash

Tracing output with line numbers

Problem:

When coding AS3, the trace() function comes in very handy for debugging.
In some cases however, it can be quite annoying as well. Sometimes you don’t remember where you put the trace() action,
or you get an output, from which you don’t know exactly where it comes from. Also, when adding trace() actions,
it can take you some seconds to find where this trace() -code is written, especially in bigger classes or functions.
A few seconds might not seem much, but at the end of the project, it’ll be a lot of seconds lost, and a lot of frustration comes along with it.

Solution:

I’ve written a class called DebugTracer, which will output your message, and add a prefix to it, which indicates the ClassName and line number of the trace action.

How it works:

It’s a bit of a trick. Line numbers are not directly accessible in AS3.
However, when an error occurs, the error information output contains the ClassName and line number of the code that generates the error.
In AS3, we refer to this info as the stackTrace. So the trick is to create an error object, and get this information out of the errors stackTrace.

Example:

Let’s output a classic “Hello world”.
Using the basic built-in trace() action:

trace ("Hello world");
       // output: Hello world

And now the same thing with the DebugTracer class:

DebugTracer.getInstance().report ("Hello world");
       // output: DebugExample (Line 21): Hello world

Additional Info:

Because the DebugTracer class works with errors, it needs a debugger version of flash player to make this work.
Also, in order to get the line number, you need to check “Permit debugging” option in the Publish Settings>Flash.
If not, only the ClassName will be added to the prefix.

Files:

You can download the DebugTracer Class here:
DebugTracer.zip

No Comments

full screen swf flash background

The problem:

For a project we were trying to make a Drupal based site a bit more attractive, by adding a full screen flash background.
The SWF had to scale with the browserwindow - and stay fixed in the window during scolling.

The solution:

HTML:
Make sure the flash div comes first - otherwise it won’t work.

since this solution doesn’t work in IE6 (go figure) - we only embed the swf when your browser is greater than IE6

<!--[if gt IE 6]><!-->
<div id="flash">
   place your swf here
</div>
<!--><![endif]-->

<div id="wrapper">
   your sites content
</div>

 

CSS:
We position the flash div fixed to the upper left corner of the . This way the flash stays on the same place while scrolling.
The Z-indexes make sure the Flash div is positioned behind the website content.

#flash {
   background-color: #000000;
   height: 100%;
   position: fixed;
   top: 0;
   width: 100%;
   z-index: 0;
}
#wrapper {
   position: relative;
   z-index: 1;
}

Further issues:

  • doesn’t work in IE6
  • no mouse pointer in Safari when hovering over links (even when added in CSS)

, , ,

6 Comments