3 Replies Latest reply on Jun 19, 2007 8:52 PM by arieljake@yahoo.com

    Mysterious Metadata error

    eight17
      I have been using Flex 2 only a short few months, but I am familiar with how using custom events works. However, I am getting a compile error on a component for which I am trying to add a custom event. Here is the code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="h t t p://www.adobe.com/2006/mxml">

      <mx:Metadata>
      [Event(name="userSelected", type="events.UserEvent")]
      </mx:Metadata>

      <mx:Script>
      <![CDATA[
      import mx.collections.XMLListCollection;
      import mx.collections.ArrayCollection;
      import events.UserEvent;
      import vo.UserVO;

      [Bindable]
      private var userList:ArrayCollection = new ArrayCollection();

      [Bindable]
      private var selectedUser:UserVO;
      ...
      private function editUser():void {
      selectedUser = userDataGrid.selectedItem as UserVO;
      var userEvent:UserEvent = new UserEvent(selectedUser, "userSelected");
      dispatchEvent(userEvent);
      }
      ]]>
      </mx:Script>

      <mx:DataGrid id="userDataGrid" dataProvider="{userList}" top="0" left="0" right="0" bottom="30" />

      <mx:HBox id="userEditBox" left="0" right="0" verticalAlign="right" bottom="0">
      <mx:Button id="cancelButton" click="cancelEditUser()" />
      <mx:Spacer width="100%" />
      <mx:Button id="addUserButton" click="addUser()" />
      <mx:Button id="editUserButton" click="editUser()" />
      </mx:HBox>

      </mx:Canvas>

      This code produces an "Only metadata is allowed" error in an arbitrary line inside the Script tag. I know this because I added, removed and commented ActionScript in the Script tag and the error stayed on the same line - even if it was just a comment line!

      Here's the kicker: When I remove the Spacer element I do not get the error!

      Has anyone else encountered this unusual error? Does anyone have an idea on how to resolve this problem? I need an answer soon.

      Thanks!