August 3rd, 2009

ronin

Hey Adobe, how come focusRect doesn't work?


http://rmirabelle.typepad.com/flash/2009/05/as3-focus-rect-and-focus-fixes-galore.html

I'm reminded of something Alan Kay said: "Simple things should be simple, complex things should be possible."

Flash fails the first half of this maxim. Fails it constantly. Simple things are almost never simple in Flash.

Other fun gotchas for the beginning AS3 programmer that have bit me (again) today:

- Your Flex app has to sub-class Sprite to get a pointer to the stage (WHY??), but if you attempt to use the "this" object as a sprite (instead of declaring a variable and doing "var = new Sprite()") or do something like this.stage.addChild(this), weird things happen. Some things don't work right, some things don't work at all. You know, the standard Adobe Flash BS.

Is there any documentation about this? HELL NO. Why would Adobe want to document something that will be a huge, nasty, evil stumbling block in the way of beginning Flex programmers? You're not paying them for their software, so they don't give a shit.

You wanna know how you end up having to make .focusRect work on a Sprite?


import flash.display.Sprite;
import flash.event.*;

var mySprite:Sprite = new Sprite();

// Put something in the sprite. Remember, Flash will *SILENTLY IGNORE*
// some function calls / property changes on a blank sprite!

mySprite.addEventListener(MouseEvent.CLICK, onClick);
mySprite.buttonMode = true;

mySprite.addEventListener(MouseEvent.MOUSE_OVER, onRollover);
mySprite.addEventListener(MouseEvent.MOUSE_OUT, onRolloff);
mySprite.focusRect = true;
mySprite.useHandCursor = false; // Not strictly necessary

stage.addChild(mySprite);

public function onRollover(me:MouseEvent) : void
{
stage.focus = mySprite; // Yes, you REALLY DO have to manage this by hand! :P
}

public function onRolloff(me:MouseEvent) : void
{
stage.focus = null;
}
  • Current Music
    Dethklok - Face Fisted