Change vs Click in the Flex 3 DataGrid

April 18th, 2008

(related to a tip I found, but for Flex 3 and my own memory…)

In Flex3 you can be notified of changes to selections in your datagrid from using listeners to either the ‘click’ or ‘change’ events, the difference being that if you only listen for click events you won’t be notified when the user navigates or selects with the keyboard (obvious, but confused me for a bit). This seems a shame given Flex’s pretty good handling of keyboard navigation, so unless you only want mouse click events use a ‘change’ handler as standard.

Using a Click Handler:

<mx:DataGrid id="DG1" click="clickHandler(event)"/>
<mx:Script>
  public function clickHandler(event:MouseEvent):void
  {
      someControl.text = event.currentTarget.selectedItem.someDataField;
  } 
</mx:Script>

Using a Change Handler:

<mx:DataGrid id="DG2" change="changeHandler(event)"/>
<mx:Script>
  public function changeHandler(event:Event):void
  {
      someControl.text = event.target.selectedItem.someDataField;
  } 
</mx:Script>

FlexBuilder on Linux… what’s happening?

March 12th, 2008

I’ve been using FlexBuilder on Ubuntu for several months now, it’s got it’s oddities and the design view is missing but it mostly works fine. I’m currently using Alpha2, and it’s now telling me it runs out in 18 days. The fcsh says it will expire in 3 days. The discussion group on Labs seems to have been wiped recently and there’s zero feedback from Adobe there. There is currently no option to buy FB for linux on the Adobe site.

So Adobe, what’s going on? Is there going to be an A3? B1? Are we ever gonna get design view? When can I buy the damn thing? Is anybody out there??

Targeting movieclip from an AS3 class file - reply

January 15th, 2008

This is a reply to Brian Chau’s post here, but my comment didn’t go through too well, so I’ll repeat it here…

————————————-

As Tink says, it’s normally better to encapsulate the functionality of each class using events and public methods instead of exposing the internals.

For this simple example, you might rewrite it something like…

Test.as

package
{
 import flash.display.MovieClip;
 
 public class Test extends MovieClip
 {
  private var blackbox_mc:BlackBox;
	 
  public function Test()
  {
	blackbox_mc = new BlackBox();
	this.stage.addChild(blackbox_mc);
	var myTest:Control = new Control(this);
  }
  
  public function positionBlackBox(x=null,y=null) : void {
	blackbox_mc.x = (x==null)?blackbox_mc.x:x;
	blackbox_mc.y = (y==null)?blackbox_mc.y:y;
  }
 }
 
}

Control.as

package
{
	import flash.display.MovieClip;
 public class Control
 { 
  private var view:MovieClip;
  public function Control(mc:MovieClip)
  {
	view = mc;
    view.positionBlackBox(null,100);
  }
 }
}

..although to me this still feels a bit odd as the main class is the view, it kinda shows how to break the two. The controller only knows what to view controll and what public methods it’s allowed to call on the view, nothing of how the view works internally.

If you then want to use a design time created blackbox you can simply plop the mc on stage, call it blackbox_mc and delete the instantiation references from the view, e.g….

Test.as

package
{
 import flash.display.MovieClip;
 
 public class Test extends MovieClip
 {
	 
  public function Test()
  {
	var myTest:Control = new Control(this);
  }
  
  public function positionBlackBox(x=null,y=null) : void {
	blackbox_mc.x = (x==null)?blackbox_mc.x:x;
	blackbox_mc.y = (y==null)?blackbox_mc.y:y;
  }
 }
 
}

As the blackbox_mc is already on the views stage flash auto creates the reference, so you can just use blackbox_mc without creating it.

Hope that helps.

A

Flosc AS3 Classes

March 2nd, 2007

Flosc (Flash Open Sound Control) is a project by Ben Chun that looks like it’s been around for a while but I’d never heard of until I had call to use it in FWiidom.

In fact I’d never heard of Open Sound Control either, but apparently it’s intended as something akin to clunky old MIDI, but over TCP. Flosc is a little Java server that sits and intercepts OSC packets and turns them into Flash XML packets. The classes in the zip below will allow you to connect easily to the Flosc sever and send and receive events and data to any connected OSC device.

I was using these classes for two way communication between Flash and Glove Pie (and thus the Wiimote) and it all worked fine. In theory you should be able to control any OSC device, including some pretty cool sound kit such as MaxMSP or Traktor.

>> Download Flosc AS3 Classes <<
This zip just contains the new AS3 classes, you’ll still need to get the main Flosc files.

Realtime webcam to Ascii converter in Flex2/AS3

January 19th, 2007

So I’ve been spending some downtime converting some old projects to AS3, one of which is an old Webcam to Ascii experiment.

While it worked OK in AS2 it was pretty lacking in the speed department, meaning you couldn’t convert at any great resolution (about 20*20 ascii ‘pixels’ was tops). In AS3 however it’s a whole different story, as this demo shows …

webcam_ascii.gif
(click the image to launch, latest FP9 & a webcam required, right click to go fullscreen)

Oh yeah, cheers Tink for the Flex help, it’s clever this Flex stuff, init?!