2 Replies Latest reply on Mar 13, 2008 12:51 PM by ntsiii

    XMLList node items to Class


      I am using adobe's sample code on how to use a Tree component and I am trying to make it open a popup TitleWindow on every selection change. The problem is that I am unable to figure out how to make the selected item Class and the debugger gives a Type Error about conversion of XMLList to Class. What am I doing wrong? :(

      This is my code:

      public var selectedNode:XML;
      public function treeChanged(event:Event):void {
      selectedNode=Tree(event.target).selectedItem as XML;
      import mx.managers.PopUpManager;
      var selectedItem:Class = selectedNode.win;

      and on XMLList I have

      <node label="Sample Label" win="mmenu"/>

      mmenu.mxml exists in my project with a titlewindow to be used as popup

      What am I missing?

      the error is like TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@6d25fd1 to Class.

      Thanks in advance...
        • 1. Re: XMLList node items to Class
          Gregory Lafrance Level 6
          Maybe more complete sample code.
          • 2. Re: XMLList node items to Class
            ntsiii Level 3
            First, PopUpManager requires a class in that arg, not the string name of a class. You need to rethink this perhaps. There are ways to instantiate class instances from a string, try searching/googling that.

            This: "selectedNode.win" returns an XMLList, all e4x expressions do. Hence the error message when you attempt to assign it to a var typed Class. Now, used correctly, since that expression references a text node, it returns text as you expect. I believe the class is using toString() on the XMLList behind the scenes.