« October 2006 | Main | January 2008 »

December 14, 2007

Setting itemRenderer in Actionscript

Some things seem so straight-forward once you figure them out, but sometimes it takes some experimenting to find the working solution. One thing I got stumped on for a bit recently was trying to set an itemRenderer in Actionscript. So I thought I'd share this one-liner -- you just have to cast it as a ClassFactory:

listObj.itemRenderer = new ClassFactory( com.martine.components.myItemRenderer );

December 13, 2007

Events can be fake.

I'm currently creating an app where I make a TileList scroll when the cursor is over it and far enough to either side. I found that if the cursor is left in place while the TileList moved underneath it, the itemRollOver event wasn't getting fired so the rollover highlighting of the TileList items wasn't working. It only works if the cursor itself is moving. Alex Harui pointed me in the direction of faking an event. It took me a little while to figure out exactly which event on which object to have trigger it (i.e. I kept trying it on the itemRenderer itself.) In the end, the solution was simple. On the TileList I jsut captured mouseOver: mouseOver="{itemRolledOver(event)}" Then created this method:
private function itemRolledOver(event : MouseEvent) : void
{
      var mouseOverEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_MOVE, true, false, event.localX, event.localY);
      event.target.dispatchEvent(mouseOverEvent);
}
... and voila! My rollover highlighting was back!

Beta's, Beta's, and the things you build.

I hope y'all are all enjoying your Betas 3's! AIR and Flex have come a long way this year and it's so exciting to see what everyone's building both internally at Adobe and out there in the "real world". We've gotten a lot of great feedback along the way too. I just got to play with Brio ( http://labs.adobe.com/technologies/brio/ ) for the first time, and it seems super cool and we're constantly seeing new sites pop up out there that blow us away. Keep it up! With the Flex framework being open-sourced and now BlazeDS remoting and messaging being out in Beta and open-source I really can't wait to see what people do. It's been 'scenario' time lately for some of us on the Flex team where we build applications with Flex and see how the experience is, what we've done well and what we can do better. It's a really fun time! Now back to coding...