0 Replies Latest reply on Apr 26, 2010 10:00 PM by Burton Radons

    Factory list menu implementation

    Burton Radons

      I'm building an application where I want to have a drop-down menu to select an object type (in this case an image filter, essentially) to create an object to append to a list. I thought to do it like this:

      <mx:XML format="e4x" id="dElevationProcessors">
              <root>
                  <menuitem label="Clear to value" classRef="{ClearToValue}" />
              </root>

      </mx:XML>

       

      ...

      <pg:DropDownButton menuData="{dElevationProcessors}" itemClick="new event.item.@classRef ();"></pg:DropDownButton>

       

      Where DropDownButton is a derivative class that creates the menu and relays its MenuEvent.ITEM_CLICK event to the object. The compiler rejects this, however, saying that "Attributes are not callable". If I replace the itemClick code with "var c: * = event.item.@classRef; new c ();", then the runtime instead fails on it, saying that "Instantiation attempted on a non-constructor." The interesting thing is that if I replace the itemClick with "trace (event.item.@classRef == ClearToValue);", this returns false. Yet "trace (event.item.@classRef, ClearToValue)" prints "[class ClearToValue] [class ClearToValue]". I also tried "var c: Class = event.item.@classRef as Class; trace (c != null, ClearToValue != null);"; that prints "false true".

       

      I assume this is some kind of weird interaction with binding, that I'm actually dealing with a binding rather than the class object itself, and while that normally doesn't make any difference, it does for new.

       

      If this can't work, then how best to implement something like this? Preferably not purely programmatically - the purpose of the project is to teach myself MXML. Obviously I could just replace the menu with a list of objects and be done with it in seconds.

       

      I'd also be interested if anyone has a cleaner, more maintainable method for doing this kind of task. Ideally all non-abstract ElevationProcessor derivates in the project would just be in a list, so I'm not replicating information in two places.

       

      If it makes a difference, I'm using FlashDevelop 3.0.6, with the latest Flex compiler, targeting Air with Flash Player 10. Thanks for any help!