Wednesday, March 14, 2007

Specifying children for derived MXML containers can be done at only one place

Error: Multiple sets of visual children have been specified for this component (component definition and component instance). is thrown by Flex when developers attempt to define children at two different places for a container. Suppose we have MyFirstBox extending HBox as follows: MySecondHBox.mxml
   <mx:HBox mx="http://www.adobe.com/2006/mxml">

      <mx:Button label="Button in declaration"/>
 
   </mx:HBox>
And we are trying to use MyFirstBox in another container like this
  <Application>

    <MyFirsthBox>

      <mx:Button label="Button in Instance" />

    </MyFirstHBox>
  </Application>
Flex throws the exception because it finds that in the declaration as well as in the instance inside the application child buttons are being added. This may be very easy to catch but where it bites is when we are trying to create a hierarchy of MXML components. Suppose we try to create a second HBox derived from MyFirstBox as follows MySecondHBox.mxml
  <MyFirstHBox xmlns="*" mx="http://www.adobe.com/2006/mxml">

    <mx:Button label="Button in derived comp" />


  </MyFirstHBox>
This is also not allowed as it falls under the same category and Flex throws the same exception. The workaround is to define children only in the leaf derived class. Any solution?

Sunday, March 4, 2007

Coding problem in ActionScript

The following code generates a VerifyError when getInstance is called. VerifyError: Error #1030: Stack depth is unbalanced. 0 != 1. at SingletonTest$iinit() public class SingletonTest { private static var s_singleton:SingletonTest = null; public static function getInstance():SingletonTest { if (s_singleton == null) s_singleton = new SingletonTest(); //Fails at this line. return s_singleton; } public function SingletonTest() { super; try { } catch (e:Error) { } } } Can you guess why? The reason is the super call in the constructor which is missing the () ! Why wouldn't the compiler throw a error or ignore the statement?

Friday, February 23, 2007

ResourceBundle Tag should match the name of properties file

Unable to resolve a class for ResourceBundle: xxx.

is a very frequent error thrown by the MXML compiler when we are including different SWCs as libraries or trying to create a new resource by creating a new yyy.properties file and trying to use it in a AS class file by using the [ResourceBundle] tag. The key is to remember that the name given in the tag should match the properties file name. So for yyy.properties file one should use [ResourceBundle("yyy")] . Even if you are using a zzz_rb.swc file containing the resources and you want to use the yyy resource present in the swc we should use the [ResourceBundle("yyy")] tag in AS file.

Saturday, February 17, 2007

About Flex

I joined Macromedia (now Adobe) in 2005 July after spending more than 7 years in Tata Elxsi. I opted to switch from Maya, 3D Graphics, C++ programming to Flex, ActionScript and Player. After learning about blogging from Manish and reading blogs from Ely, Kevin Lynch, Raghu and various other people I also wanted blog separately on Flex but never thought my knowledge enough to enough to write one. After a year or so I am feeling that I could put together a blog with lot of "pearls" I keep picking up from the DL-Flex Questions mailing list so that including myself anyone can make use of these.