Archive for the 'ActionScript' Category

Grant Skinners 50 reasons why AS 3 kicks ass

I found great slides on Grant Skinners blog. They give a quick introduction in AS 3 and it’s core benefits!

50 reasons why AS 3 kicks ass (Grant Skinner)

Also a must read for developers!

Update: And he also added more slides from a workshop here

Using Sprite.buttonMode and Sprite.mouseChildren

Today I found something I really did not understand very well. I had to debug a application because one button displayed the handCursor and another did not. Both use the same script and actually I didn't find out why the behaviour of this buttons was like that but I fixed it through a workaround.

The first thing I understood today is, that it's possible to receive all mouse events without using buttonMode! Simply add a listener to your objects and you can work with them.

But if you like to work with a button that contains additional sprites (which might be very useful) you definitely should take care about their behaviour. By default mouse events will be dispatched by the lowest sprite, exept you set mouseChildren to false...

Have a look at this little code example:

Actionscript:
  1. package {
  2.     import flash.display.Sprite;
  3.     import flash.events.Event;
  4.     import flash.events.MouseEvent;
  5.  
  6.     public class ButtonModeTest extends Sprite
  7.     {
  8.         public function ButtonModeTest()
  9.         {
  10.             run();
  11.         }
  12.        
  13.         private function run(): void
  14.         {
  15.             //-- Start listening
  16.             addEventListener( MouseEvent.CLICK, onMouseEvent );
  17.             addEventListener( MouseEvent.MOUSE_OVER, onMouseEvent );
  18.             addEventListener( MouseEvent.MOUSE_OUT, onMouseEvent );
  19.            
  20.             //-- Button 1 on the main stage
  21.             var button1: Sprite = createButton( 1 );
  22.             addChild( button1 );
  23.            
  24.             //-- Button 2 within the container
  25.             var button2: Sprite = createButton( 2 );
  26.             var button2Container: Sprite = new Sprite();
  27.             button2Container.addChild( button2 );
  28.             button2Container.x = 150;
  29.             button2Container.name = "button2Container";
  30.             addChild( button2Container );
  31.            
  32.             // By default the mouse events will be dispatched by the buttons themself
  33.             // (the lowest sprites)
  34.            
  35.             // Setting containers buttonMode to true doesn't force the container to
  36.             // dispatch the mouse events ( so what the hell is button mode?)
  37.             button2Container.buttonMode = true;
  38.  
  39.             // Setting containers useHandCursor to true only works when it's buttonMode
  40.             // is also true. But the events will still be dispatched from the lowest
  41.             // sprite (even its a button!?!)
  42.             button2Container.useHandCursor = true;
  43.            
  44.             // Only setting mouseChildren to false forces the container to dispatch
  45.             // the mouse events
  46.             button2Container.mouseChildren = false;
  47.         }
  48.        
  49.         private function createButton( index: uint ): Sprite
  50.         {
  51.             var button: Sprite = new Sprite();
  52.             button.name = "button" + index;
  53.             button.graphics.beginFill( 0, 1 );
  54.             button.graphics.drawRect( 0, 0, 100, 100 );
  55.             button.graphics.endFill();
  56.            
  57.             return button;
  58.         }
  59.        
  60.         private function onMouseEvent( event: Event ): void
  61.         {
  62.             trace( "Event (" + event.type + ") dispatched from : " + event.target.name );
  63.         }
  64.     }
  65. }

AVM1 _globals are still global.

This is one of this quicknotes just for not forgetting a simple issue:While developing a "AS2Wrapper" for embeding AS2 contents in AS3 applications I recognised that _globals within the loaded AS2 SWFs still exist when you unload this SWF and load another. This seems to be quite apparent but I thought about the AVM1 as some kind of sandbox.

AS3 Spell Check Engine

Grand Skinners Spell Check Engine could be really interessting for business projects. So keep it in mind!

ActionScript Performance Test

This performance test shows how fast the ActionScript AVM2 runs compared to the AVM1, Java(!) and JavaScript: See it