Posts Tagged ‘class’

Pure Actionscript 3 Window Class

Thursday, November 13th, 2008

I’ve been working on an easily skinnable windowing system, and this is what I have so far. I’ve attempted to mimic mac’s theme for Leopard.

Actionscript 3 Leopard GUI

Actionscript 3 Leopard GUI

The source and documentation are in their usual spots -> My classes. I’ll be updating them pretty regularly. Here’s the source for the project itself -> project source

Flash Actionscript 3 Waveform Generation Class

Friday, October 24th, 2008

In my last post, Plotting a Sound Wave in Flash AS3 I detailed a method to use when displaying audio data. The method itself works great, but due to Flash’s frame-based code execution and event processing the user looses input capabilities while the flash player chugs through millions of numbers adding, rounding and comparing. In order to make displaying an audio waveform easier on both the programmer and the user I wrote a class that analyzes a Sound object progressively, and dispatches a special event containing the analyzed data. The class will construct a left and right channel Vector, each containing one data point [a number between 0 and 1] for a given number of windows, between two positions in the sound. The left and right position are measured in samples and two types of analyzation are offered. Here is a demo of the class in action:

Screen Capture of Waveform Plot

Screen Capture of Waveform Plot


The calculated data can be reached incrementally through the WaveformEvent object which is dispatched every frame, or at the end of all analyzation in the Waveform object’s leftChannel and rightChannel properties. The details are listed in the documentation below.

Thanks to the Summit Projects Flash Blog and Thibault Imbert at ByteArray for their posts on the different techniques that went into my class.

Source
Here is the source for my TextMate project: Sources
Documentation: class and event

And here is a Flex version (made in windows): // Thanks dem!
Sources (Flex version)

AS3 Classes and Interfaces Quicktip

Saturday, January 19th, 2008

Interfaces in AS3 are super useful for requiring classes to support a set of public methods, enabling other classes to communicate through the interface thereby abstracting the class itself. AS3 doesn’t natively support abstract classes so using Interfaces is a good replacement in some cases, but if you’ve never used an Interface before you probably wouldn’t know how to implement it. The docs help a little, showing you how to instantiate a class using an interface with the “implements” keyword, but doesn’t go much further:

public class myClass implements myInterface{
}

But what if you’d like to implement a class while extending another? Well, it’s simple once you know the syntax…

public class myClass extends baseClass implements myInterface {
}

This is a very quick and simple tip that took me a while to find online due to the fact Adobe doesn’t mention it. Such a simple thing should be in the help docs, but I guess adobe thinks that anyone trying to use Interfaces would already know the syntax! Well now you do.

Multiple Bitmap Loader in AS3

Sunday, November 25th, 2007

To aid in my projects I have written a simple bitmapData loading class entitled aquireResources. This class takes an array of image paths as strings and proceeds to load them one by one. A “complete” event is dispatched when loading is completed and the bitmapData of each loading instance are saved in an array in the order they were given. Calling the aquireResources.array() method returns the array of bitmapData. If you’ve already downloaded Thibault Imbert (bytearray.org)’s GIFPlayer and GIFDecoder classes you can uncomment the included properties and methods in my class and enable the aquireResources class to load multiple instances of animated GIFs into AS3 as arrays of bitmapData. In this case aquireResources.array() returns a two-dimensional array containing one array of bitmapData per animated GIF passed to it.

Usage

import com.efnx.utils.aquireResources;

var rsrc:aquireResources = new aquireResources();
     rsrc.addEventListener("complete", onComplete, false, 0, true);

var array:Array = new Array("imagePath1/image1.png", "imagePath2/image2.gif", "imagePath3/image3.jpeg");
var bitmapDataArray:Array;
function onComplete(event:Event):void
{
     bitmapDataArray = rsrc.array();
}

rsrc.aquireImages(array);

For loading animated GIFs

import com.efnx.utils.aquireResources;

var rsrc:aquireResources = new aquireResources();
     rsrc.addEventListener("complete", onComplete, false, 0, true);

var array:Array = new Array("imagePath1/image1.gif", "imagePath2/image2.gif", "imagePath3/image3.gif");

var animatedArray:Array;
function onComplete(event:Event):void
{
     animatedArray = rsrc.array();
}

rsrc.aquireGIFs(array);

Source
aquireResources Source

Simple Tiling Sprite Class in AS3

Monday, November 19th, 2007

Also known as “Developing a Pure AS3 GUI – Part 1.5 (tile)
Jump to Source
After writing last night’s class, scalingBars, I decided to make it a little easier on myself to tile bitmaps across the screen. I wrote a simple class that when given either a BitmapData object or a path to an image file (as a String), class will tile the image x pixels in width and y pixels in height. This is great for backgrounds or window bars or box sides, etc. Here’s the usage:

var bar:tile = new tile("pathToImageOrBitmapDataObject", 100, 150);
     addChild(bar);

The previous code will grab an image from “pathToImage” [either relative or absolute, but remember security!] and then tile it 100 pixels wide by 150 pixels tall. Simple. Now let’s say you wanted to resize it:

bar.resize(20, 40);

That code will re-tile the image to 20 pixels by 40 pixels. Next on my list of upgrades is to allow reloading of different images. Shouldn’t be too hard.
Example

Source
tile Class Source Code


Follow me on GitHub
Follow me on Google+
Follow me on Twitter