nulldesign // lars gerckens » Actionscript

Archive for category ‘Actionscript’

   

F10 Astro Blackhole

The Flash 10 beta player is out for a while and I found a few minutes to try out the new native 3D effects. You can get quite nice and fast results out of the new API if you only want to display flat 2D planes in 3D-space:


(Space = fullscreen, Download source, Flash Player 10 needed)

Posted in 3D, Actionscript, Experiments, Flash 10, Particles, Source | 4 Comments »

ND3D engine goes google.code

Good news everyone! I packed everything together, cleaned up a bit and created a google.code project for my 3D engine. Since it became popular under the name ‘nulldesign’s 3d engine’ I call it ND3D from now on ;). I will post additional infos, more examples and future developments here in my blog and on the project page. So long…

Posted in 3D, Actionscript, Experiments, Flash 9, Source | 6 Comments »

Flex: Adding a tooltip to truncated Datagrid columns

I just found a nice way to automatically truncate text in datagrid columns and show tooltips for truncated elements, that I wanted to share:

package
{
	import mx.controls.dataGridClasses.DataGridItemRenderer;
 
	public class TruncateToolTipRenderer extends DataGridItemRenderer
	{
		private var textTruncated:Boolean = false;
		private var originalText:String;
 
		public function TruncateDataGridItemRenderer()
		{
			super();
		}
 
		override public function set text(value:String):void
		{
			super.text = value;
			originalText = value;
			textTruncated = truncateToFit();
		}
 
		override public function validateProperties():void
		{
			super.validateProperties();
			toolTip = textTruncated ? originalText : null;
		}
	}
}

Just set the itemRenderer property of your column to the new TruncateToolTipRenderer. Neat!

Update: … and it’s a lot easier if you just set the itemRenderer to mx.controls.Label, because a Label already has truncate and tooltip functionality. As so often in Flex, everything is built in. Lesson learned!

Posted in Actionscript, Flex | 3 Comments »

3D Engine Sources + Examples

About some time ago I started to code my own 3D engine in flash. Derived from a small AS2 project, I challenged myself to built my own flash 3D engine. So I took out my good old Actionscript Animation Book and opened the 3D chapter. Very soon I could move a cube around. A few pages later I learned how to implement simple dynamic lighting. The next challenge was to get texture mapping to work. Since flash still can’t distort images, you need a workaround. After I found these great examples: Seb Lee-Delisle’s flash texture maps and Andre Michelle’s texture examples it was done. Somewhere inbetween I switched to AS3, which was quickly done. Meanwhile Papervision3D became very popular and I thought it didn’t make sense to continue evolving my engine. But since I came so far, I needed to find out how to implement a few effects like depth of field or additive rendering ;)

My engine shouldn’t and doesn’t compete with Papervision3D or Sandy3D, nor it has a very user-friendly API, no stunning effects or animation support, but I learned a lot while building it, understanding 3D to 2D rendering, optimizing the code for a few ms of extra speed (AS3 rocks!) or challenge problems with 3D rotations like gimbal lock and their solutions: quaternions. It’s just another 3D flash engine, at least I can say: I made it! ;)

It’s undocumented, there’s still a lot of work to do and it doesn’t have a cool name , but if you want to play around with it or just take a look how I set up this and that, feel free to download the sources (yes, the 3D ribbon example is included). And I’m always interested in what you think about it, so drop a comment or mail.

Posted in 3D, Actionscript, Experiments, Flash 9, Source | 21 Comments »

Collision Tests

As you noticed, I’m building a small arcarde shooter in AS3 besides my daily work. It started as a small test and got me ;). In my previous post I used getObectsUnderPoint for a hittest between the shot and the enemyclips, this works fine if you don’t need a collision reaction and the clips travel at a moderade speed. Now I wanted to integrate a collision detection and reaction for the enemies and made use of some nice scripts I found out there:

A shape-based collision detection for bitmaps by Grant Skinner, since the third parameter in hitTestPoint(x:Number, y:Number, shapeFlag:Boolean) only works for vectorimages and I’m using bitmaps as graphics. A Proximity Manager. This small class comes really handy and the principle is so simple. The proximity manager splits the stage into grids and stores for every sprite in which grid they are. So you don’t need to test every sprite against all other sprites, instead you just say: “Give me all neighbours of that sprite”, which saves a lot of loops.

So I had the tools for a nice collision detection, for the collision reaction I converted a simple snooker algorithm to AS3: Snooker Balls. Watch the result:

Move your mouse over me!

Posted in Actionscript, Experiments, Flash 9 | 4 Comments »

It all started as a performance test…

Ok, AS3 can render thousands of particles per frame… but what if we want more than a few single moving pixels and hittests? So I started to write a small test, instancing bitmaps on random locations. And hey: These objects look like bombs, now I need something to destroy them … and there was the battleship ;). For the hittest I used getObjectsUnderPoint. It seems like this method is a bit slower than hitTest or hitTestObject, but you can actually save a lot of loops because you don’t need to test each bomb with each shot. Instead of:

// pseudo code
for each(bombs) {
    for each(shots) {
        if(bomb.hitTestObject(shot)) {
            // shot hit bomb...
        }
    }
}

you go:

// pseudo code
for each(bombs) {
    var objects:Array = shotClip.getObjectsUnderPoint(bomb.x, bomb.y);
    if(objects.length) {
          // shot hit bomb...
    }
}

This only works, if you have a seperate clip for the shots. Enough of the talk: Launch!


(Move using the mouse and rotate the gun with cursor keys)

Posted in Actionscript, Flash 9 | 2 Comments »

AS3 Preloading continued

I wasn’t really satisfied with the solution I used for my AS3 preloader (see post: Preloader in AS3 projects). Now Sven found THE solution. It’s in german, so I try to explain how it works:

The class “Test” acts as the factory class that’s responsible for the preloading. The Class “Demo” is the main application class. Using the compiler option -frame frameLabel Demo, the class Demo is compiled into frame 2.

Just like in Keith Peter’s Example and my try using an exclude xml, you can preload a pure AS3 application now, but in this case no flex framework classes are compiled into the resulting SWF and there is no need for an exclude xml. Finally!

Posted in Actionscript | 9 Comments »

AS3 Singletons, the other way

Since you can’t declare a constructor private in AS3, there are a few methods out there to enforce a Singleton. A common way is to declare an internal SingletonEnforcer class outside the package: SingletonEnforcer, but the declaration of the Enforcer outside a package looks a bit “dirty” to me. Another way is to declare the singleton as a static variable, but this way you can’t decide when your singleton is instantiated.

So, why don’t just try nearly same with a local variable:

package {
    public class Singleton {
        private static var instance:Singleton;
        private static const checker:Object = {};
 
        public function Singleton(initObj:Object) {
            if(initObj != checker) {
                throw new Error("Private constructor!");
            }
        }
 
        public static function getInstance():Singleton {
            if(instance == null) {
                instance = new Singleton(checker);
            }
            return instance;
        }
    }
}

Update: I found another nice solution by GSkinner: SingletonDemo.

Posted in Actionscript | No Comments »

Preloader in AS3 projects (factoryClass)

The last days I was playing around with the Flex Metadata Tag “Frame” to implement a preloader in an AS3 project. You might have read Keith Peters post concerning this issue. This method is working fine, except of the fact that I can’t get rid of the flex framework classes in my compiled SWF, which blows up the size of an nearly empty SWF to 120kb.

If you check out the comments in his post, you’ll find a few solutions, but none of them worked for me. So I generated a XML exclude File, that excludes the whole flex framework. You might want to give it a try: flex_framework_exclude.xml (compile with the option -load-externs+=flex_framework_exclude.xml). It’s still not satisfying, but it’s working…

Posted in Actionscript | 3 Comments »

Custom right click menus in AIR

I was wondering, why DisplayObjects in AIR don’t support the MouseEvent.RIGHT_CLICK Event. The only way to implement a right-click-menu seemed to be a NativeMenu. But I needed only the event, not the ugly native-os-menu.

Here is the workaround: Just create a blank NativeMenu and listen for the display event.

var menu:NativeMenu = new NativeMenu();
menu.addEventListener(Event.DISPLAYING, onRightClick, false, 0, true);
someSprite.contextMenu = menu;

Posted in AIR, Actionscript | No Comments »

New site, new blog

Good news everyone!
I removed my three year old flash site and managed to set up this blog instead. I think this is a much better place to showcase my experiments. It’s not finished yet, but I’m working hard on it to get everything done.

I will post news, talk about my flash experiments, actionscript in general and whatever pops into my mind here.
So, let’s get started!

Posted in Actionscript | 2 Comments »

   

About

  • nulldesign is the company and showcase site of freelance developer Lars Gerckens who is based in Hamburg, Germany. I'm available for freelance work with focus on Flex, Flash and AIR development. I like to create dynamic user interfaces, cutting edge web experiences and innovative ways to visualize data.

    This site showcases some of my personal work and projects as well as an selection of commercial projects.

    If you are interested in my work or you have any questions, don't hesitate to drop me a line:

  • Profiles: Xing | Linkedin
  • Mail: lars [at] nulldesign [dot] de

Categories

Search