Something Wrong with the System

A Flash/Actionscript blog

FadeSound AS3 – A class which fades sounds in and out automatically

Get Adobe Flash player

Recently I was working on a project that required me to fade a sound in and out dynamically. Here is the result:

FadeSound (clever name, huh?) is an AS3 class that extends Flashs built in Sound class and includes fading in and fading out (including auto-fade out on sound completion).

Here is the source:

You can probably just dive in and figure it out based on the examples, but I’ll do a write-up after the break.

Read the rest of this entry »

December 27th, 2010 by Peter Organa
Posted in AS3, Programming, Source Code | Comments Off on FadeSound AS3 – A class which fades sounds in and out automatically

Making AS3 components is harder than I’d imagined…

I’ve updated the Flash Pie Chart, made it more awesome and put it up for sale on ActiveDen as a Flash component and Flex Class!
Check it out! It’s pretty rad!

So as I wrote earlier I’m working on transforming my 3D Pie Chart into a proper AS3 component.  Holy crap, it’s harder than I thought!

By far the most useful resource I’ve found is this one written by Jeff Kamerer from Adobe.  The document is divided into 9 parts (it’s a small book!) and covers:

I’ve trudged my way through the first 3 parts and… GREAT SUCCESS!  I’ve got my Pie Chart publishing from a component inspector window (shown on the left).

The bit of code that caused me the most grief is the section that pertains to the dataProvider.  It seems that if I want custom parameters in my Component Inspector I need to create my own DataProvider classes.

[Collection(collectionClass="ca.organa.Data.Collect", collectionItem="ca.organa.Data.ComponentInfo", identifier="sliceLabel", name="Pie Chart Data")]
 public function set dataProvider(value:Collection):void {
 if (_dataProvider != null) {
  _dataProvider.removeEventListener(DataChangeEvent.DATA_CHANGE, handleDataChange);
  _dataProvider = value;
  _dataProvider.addEventListener(DataChangeEvent.DATA_CHANGE, handleDataChange, false, 0, true);

Jeff covers the topic here.

I’ll post about components again once I’ve gone further into this stuff.  My next challenges are going to be getting live preview working, and getting a proper colour picker in the component inspector (is that even possible?). Read the rest of this entry »

September 8th, 2009 by Peter Organa
Posted in AS3, Flash Components, Programming, Source Code | Comments Off on Making AS3 components is harder than I’d imagined…

My AS3 3D Pie Chart

I’ve updated the Flash Pie Chart, made it more awesome and put it up for sale on ActiveDen as a Flash component and Flex Class!
Check it out! It’s pretty rad!

First an FYI, this is a showing off post.  I’m not sharing the source for this as I’d like to explore the idea of selling the Pie Chart as a Flash Component.

Recently at work I’ve been doing on a bunch of charts (mostly analytics style lines graphs).  When I was finished, I thought to myself: “Well I haven’t done a Pie Chart yet”.
Ultimately, it took me 5 times longer than I would have ever expected, but I did create a fully functional 3D Pie Chart!

  • This is a true 3D Pie Chart with rotation.
  • This is done completely with Flash’s draw API, I don’t make use of Flash10 3D features or Papervision
  • The Pie chart is resizable and all the data/colours are externally configuarable.  You can even change the view angle.

Read the rest of this entry »

September 4th, 2009 by Peter Organa

2D Game Scrolling in AS3 (my very early implementation)

Level ScrollingA few weeks ago I started work on a new game as a hobby project… unfortunately I also started playing A LOT of Company of Heroes on the PC, so progress on the programming has been slow, very, very slow.

But I did write at least one useful piece of code that I think some people might find useful:  Level Scrolling.

When I was working on my first Flash 2D platform engine Sprocket (game was never finished).  I found one of the biggest problems was having the level scroll properly.  So this time when I started writing the game engine, scrolling was the first thing  I nailed down.

In Sprocket I found that scrolling with the Character locked in the center of the screen was unsatisfactory as enemies could easily sneak up behind you.  So I developed a system where the mouse controls the user’s view.  I was inspired by the scrolling in PC games such as Abuse, and Soldat.

In my new game I’ve created a LevelDisplay class which handles all scrolling work automatically. Just tell the LevelDisplay what game sprite to focus on and it will handle the rest.

Keep in mind all of this code is very early, so please don’t just plonk this in your game.  Once I’ve built an actual game I’ll have a better idea of how successful my implementation actually is.  But for now I’ll share what I have and maybe you can get some use out of it.

Read the rest of this entry »

August 23rd, 2009 by Peter Organa

PhotoPal (maybe PhotoViewr) ?

photoPal Sample Image

I spent some time the last week working on my dad’s website (he runs a portable Pet Photography Studio).  Specifically, I was working on a AS3, PHP+SQL application that would give his clients a preview of their photos before they order them.

I hadn’t worked on a PHP project in ages and the language was just as a I remembered it: Really ugly code that does exactly what I need it to do.

The Flash to PHP communication was handled via XML-RPC for PHP and XMPRC for Asctionscript 3.0.  XML-RPC is a set of libraries that help you ferry data from one system to another.  It took me a little while to get the knack for preparing the RPC Objects, but ultimately it was a painless process.

What I was left with is a (ugly as hell) back-end interface in PHP that outputs to an attractive (I think) Flash front-end.

The advantages here are:

  • My dad doesn’t need to know any code to get this to work, he browses his file system for images and the PHP code takes care of everything else.
  • Clients (who lack tech savvy) can’t download the JPEGs and print illicit images like they could with a pure HTML/PHP interface.
  • My dad doesn’t need to re-size his Images to fit flash as the PHP script will take care of that.
  • The PHP/SQL link up lets me save favourites and do per image click user tracking.
  • A Flash interface is just cooler!

I think my favourite part of this app is the Transition class, it transitions between any two display objects with a fade & re-size.  I’m using that class to display everything in the main window.  If anyone shows interest I’ll go ahead and clean up the class and post it here.

Anyhow.  You can see the app in action here.  Use ‘Reese‘ as a password.

If anyone is curious you can see my Dad’s Flickr page here.

Oh and if you’re wondering about the blog post title.  I have no idea what to call this application.  I’ll gladly take suggestions in the comments section!

July 23rd, 2009 by Peter Organa
Posted in AS3, Not Programming, Programming, Super Cool | Comments Off on PhotoPal (maybe PhotoViewr) ?

Bezier Curves AS3

Ok, so I’m coming down with a serious case of blog guilt. I haven’t posted in… well a while.

First my excuse:

I just finished a big freelance job.  Now that the job is done I can get on to some more exciting stuff!

To warm myself up. I’m posting something I played around with recently. I explored Flash’s fl.motion.BezierSegment class. It’s neat and surprisingly easy to use.

You can see the swf in motion after the break.  I’ve included the source code, enjoy!

Grab the source here

Read the rest of this entry »

July 6th, 2009 by Peter Organa

Colour Swarm – Contest Entry

I was recently invited to participate in FXpression 09.  A flash contest on  The contest rules state that all entries must be composed entirely of circles.

I entered a modified version of my swarm code.  See it in all it’s glory after the break.

Read the rest of this entry »

January 19th, 2009 by Peter Organa

Mega Swarm + AS3 optimizations

I’m still working on the flocking code I blogged about earlier.

I wanted to get more flock objects on screen.  But my nearest neighbour detection code was VERY SLOW.  In the old version each flock object would do a closest neighbor check by for looping through EVERY OTHER ENTITY on screen.  The number of calculations would increase exponentially as the number of flock entities increased.  This set a limit of about 200 entities before things started to slow down.

So I decided to add a broad level distance detection level.  My first attempt got me up to about 700, before things started to slow down.  Which was not bad but I was sure I could do better.  At this point my friend William stepped in and essentially re-wrote my code 3 times over (William is a math major, and a super smart guy).  One of his broad hit level schemes let me get up to 2000 entites on screen at once (on my home computer). The version I posted here shows 1200.

See the mega swarm in action after the break.

Read the rest of this entry »

January 18th, 2009 by Peter Organa

Swarm (nicer)

Hey guys, I made a prettier version of the Swarm app I posted yesterday.

Check it out after the break.

Read the rest of this entry »

January 8th, 2009 by Peter Organa

The Swarm

Recently I watched a video on In the video Steven Strogatz talks about sync, in one segment he speaks about flocking behavior and lists the three simple rules that govern flocking.  Later I found that this type of artificial flocking behaviour can be referred to as ‘Boids‘.

So yeah… I decided to code it up in Flash ActionScript 3.0.

The image on the left doesn’t really do the app justice.
Click more to see the app in action.

Read the rest of this entry »

January 7th, 2009 by Peter Organa