1 Reply Latest reply on Dec 18, 2008 11:31 AM by ephemerian

    How to addChild() with custom mxml component

    ephemerian
      Sorry if this is a really basic question, but I've spent a long time searching for an answer with no success.

      Suppose I create a new component QueryHandle.mxml using Canvas as the root element in the mxml file. Elsewhere in my code, I dynamically create a new instance of a QueryHandle, and try to add it as a child of a container. The compiler complains with error 1067: Implicit coercion of a value of type QueryHandle to an unrelated type flash.display:DisplayObject. I suppose I naively assumed that the component I created in the mxml file, QueryHandle, would extend Canvas as that's the root component. In which case, there wouldn't be a classcast error. However, that doesn't seem to be the case. In fact, I realised as I was researching this, that I don't actually know how a component defined in mxml, rather than actionscript, relates to the rest of the class hierarchy.

      So two questions: what do I have to do to get my code to add a QueryTemplate as a container child, and how in general do mxml components relate to the overall Flex class hierarchy?

      Thanks,
      Ian