Archive for the 'Actionscript 3' Category

New tutorial on ActionScript 3 performance testing

I just finished uploading a new tutorial showing how you can test the performance of your ActionScript 3 code. Grant Skinner recently released a great library called PerformanceTest which makes it easy to test out your code. In the tutorial I show how to use the library to test individual functions as well as a whole suite of functions. Always test out your code to be sure you’re using the fastest techniques.

Lee

New tutorial on augmented reality with FLARManager

I just uploaded a new tutorial on using the FLARManager library to create augmented reality applications. This library makes things much easier than using the FLARToolkit directly, especially when dealing with multiple markers. In this example I display a video on a 3D plane that follows the AR marker. The tutorial also covers how to properly create markers using a new online tool.

Lee

Watch Designing for Augmented Reality

Below you can watch my full session on augmented reality from Adobe MAX. I highly recommend watching this in fullscreen so you can actually make out the code snippets. I love that I had to use my backup project called IfShitFails. I will also be doing a video tutorial on using FLARManager later today.

Enjoy!
Lee

Using BitmapData.setVector for better performance

During the ByteArray workshop yesterday we wrote some code that parsed a PSD file and displayed it in the Flash Player. As part of this I showed setting the pixels of the BitmapData object using the setPixels method. I had heard that this method was slow but Thibault confirmed this for me. He suggested that I try a new method that was introduced in Flash Player 10 called setVector. This allows you to take a Vector object containing 32-bit floating point numbers and use it to set the pixels in the bitmap. Below is the original code using setPixel which required a nested for loop.

1
2
3
4
5
6
7
8
var bmd:BitmapData = new BitmapData(width, height);
for(var y:int=0; y<height; ++y)
{
    for(var x:int=0; x<width; ++x)
    {
        bmd.setPixel(x, y, r.readUnsignedByte()<<16 | g.readUnsignedByte()<<8 | b.readUnsignedByte());
    }          
}

The new code which takes advantage of setVector is shown below. There is one trick to getting this to work. You have to shift a value of 255 (aka 0xFF) to the far left byte as you need to provide an ARGB number for it to work. Otherwise your pixel would have an alpha of zero.

1
2
3
4
5
6
7
8
9
10
var numPixels:int = width*height;
var pixels:Vector.<uint> = new Vector.<uint>(numPixels, true);
           
for(i=0; i<numPixels; ++i)
{
    pixels[i] = 0xFF<<24 | r.readUnsignedByte()<<16 | g.readUnsignedByte()<<8 | b.readUnsignedByte();
}          
           
var bmd:BitmapData = new BitmapData(width, height);
bmd.setVector(new Rectangle(0, 0, width, height), pixels);

The BitmapData class is smart enough to put all the values into the right places in the bitmap so you don’t have to deal with nested loops.

Lee

New tutorial on Flash Builder 4 data integration

I just finished uploading a new tutorial that shows how easy it is to integrate server-side data into your Flex 4 applications using Flash Builder 4. In the example I display results from the Twitter search API in a datagrid without having to write a single line of code. These new features make it incredibly easy to connect to things like ColdFusion, ZendAMF, LiveCycle DS, etc. Definitely one of my favorite Flash Builder 4 features.

Lee

New tutorial on SWF framerate optimization

I just finished uploading a new tutorial that explains how you can optimize your Flash movie’s framerate so that it only uses the resources that it needs to. Most of the time you only need a fast framerate for animation and you can structure your movie so that the rate is high only during those times. The tutorial also shows how to put your movie into a different mode when the user leaves your movie.

Lee

Adjusting audio pitch in Flash Player 10

Update: Andre Michelle wrote some much better code to adjust the pitch of an external sound. I was secretly hoping he would. Check it out at http://blog.andre-michelle.com/2009/pitch-mp3. Thanks Andre!

Here is another sound example that shows how to adjust the pitch of an external sound. This is an extension of the example that can be found in the documentation for the Sound.extract method. Now this example does adjust the pitch but it also speeds the song up as well. This is because you need to skip some samples in order to increase the pitch. Now there are ways to increase the pitch of sounds without speeding them up but I have no idea how to do it. Do you?

Click on the image below to see the example. It uses my throw slider which you can toss back and forth. It may take a minute for the song to load so please be patient. You can download the FLA file if you want to see how it was done.

Lee

Next Page »