Flex Pasta » RadioButtonGroup gets special treatment

RadioButtonGroup gets special treatment

I was creating a custom component today.   I wanted to declare the component in mxml, but the component was not a visual component, just like the RadioButtonGroup class.  To create a non-visual component in mxml, just have the component implement the interface mx.core.IMXMLObject …. or so I thought.  Here is my component:

package
{
import mx.core.IMXMLObject;

public class MyNonVisualComponent implements IMXMLObject
{
public function MyNonVisualComponent()
{
}

public function initialized(document:Object, id:String):void
{
}

}
}

When I try and use the component, I get an error: Component declarations are not allowed here. (Note: visual children must implement mx.core.IUIComponent)

Wait a minute, I used the  IMXMLObject whose interface states:

The IMXMLObject interface defines the APIs that a non-visual component must implement in order to work properly with the MXML compiler. Currently, the only supported method is the initialized() method.

This is exactly how the mx.controls.RadioButtonGroup class does it too(Check out the source of it if you don’t believe me)!!!   So after an hour trying to figure out why something so simple doesn’t work I found my answer deep inside the compiler source code.  It appears the compiler gives special treament for RadioButtonGroup when it compiles instead of to IMXMLObject.

In flex2.compiler.mxml.builder.ComponentBuilder.java:

else if ((standardDefs.isContainer(parentType) && childType.isAssignableTo(standardDefs.CLASS_RADIOBUTTONGROUP)) ||
(child instanceof ReparentNode))
{
ComponentBuilder builder = new ComponentBuilder(unit, typeTable, mxmlConfiguration, document, component, null, null, true, null);
child.analyze(builder);
}

Therefore, unless I am missing something, I can’t create a non-visual component for mxml.  Thought I’d pass this info along to anyone else who is banging their head against a wall!

I opened a ticket with Adobe to fix the problem.

5 Comments

  • 1. Tony Fendall replies at 2nd November 2008, 6:24 pm :

    I have to admit I have never looked into the issue in detail, but I often create non-visual objects in MXML. The most common use case for me is declaring an ArrayCollection.

    I know that the ArrayCollection class does implement IMXMLObject. I wonder if the same exception is applied to this class also?

  • 2. Brian Telintelo replies at 3rd November 2008, 5:30 pm :

    Hi Tony,

    I just tried using an ArrayCollection and I get the same error. I did notice that the error goes away if the non-visual component is a child of mx:Application, but in all other instances the error occurs.

    Brian

  • 3. Ray Pendergraph replies at 22nd February 2009, 2:00 pm :

    Thank you for posting this. Very informative. I saw a group post somewhere else where it looked like one of the developers said (paraphrased)”Oh yeah, I thought we removed that restriction.” I guess not.

  • 4. SDK replies at 2nd September 2009, 1:48 pm :

    could you give the adobe support ticket number to keep track of it ?
    THANKS

  • 5. Brian Telintelo replies at 6th September 2009, 8:16 am :

    https://bugs.adobe.com/jira/browse/FCM-2

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>