Journal Entries

 

Apr 6, 2009

Thus begins “The Fun!”


I’ve started using Flex in a big way at work. And that, of course, means that I’m at the beginning of the learning curve where the most basic issues take days to trouble shoot. Take the following example:

While creating the view for a basic MVC, I extended the Panel component, added a TextField and ran it. Flex blew up with errors.

package
{
	import flash.events.Event;

	import mx.containers.Panel;

	public class TestPanel extends Panel
	{
		private var __tempTextArea:TextArea;

		public function TestPanel()
		{
			super();
			__tempTextArea = new TextArea();
			__tempTextArea.x = 330;
			__tempTextArea.y = 82;
			__tempTextArea.width = 680;
			__tempTextArea.height = 625;
			addChild(__tempTextArea);
		}

		public function onChange(e:Event):void
		{
			trace("onChange from TestPanel");
		}

	}
}

Two days pass. Then comes a solution. It seems that any visual component in Flex MUST either extend mx.core.UIComponent or implement mx.core.IUIComponent.

package
{
	import flash.events.Event;

	import mx.containers.Panel;
	import mx.core.IUIComponent;

	public class TestPanel extends Panel implements IUIComponent
	{
		private var __tempTextArea:TextArea;

		public function TestPanel()
		{
			super();
			__tempTextArea = new TextArea();
			__tempTextArea.x = 330;
			__tempTextArea.y = 82;
			__tempTextArea.width = 680;
			__tempTextArea.height = 625;
			addChild(__tempTextArea);
		}

		public function onChange(e:Event):void
		{
			trace(”onChange from TestPanel”);
		}

	}
}

I’d point you to the line in the documentation that makes this explicit and call myself an idiot, but I can’t. The Flex documentation is extremely lacking and obfuscated. If I have a problem with Actionscript, I pop open Flash’s documentation. If I have a problem with Flex, I pop open the Google.

 

Leave a Reply