1 Reply Latest reply on Nov 25, 2007 6:44 PM by peterent

    How to separate embedded ActionScript from MXML

    Mxmler
      Hi all,

      I need to separate the embedded ActionScript codes located in between <mx:Application> tags (inside MXML). I need to
      do this, becuse it will help me to simplify my job.

      The embedded ActionScript code looks like this:

      <mx:Script>
      <![CDATA[
      private var services:RemoteObject;
      public function initApplication():void
      {
      services = new RemoteObject("GenericDestination");
      services.source="com.mydomain.Services";
      services.authorizeAccessTicket.addEventListener(ResultEvent.RESULT, loginResultHandler);
      }
      .
      .
      .
      ]]>
      </mx:Script>

      Once I taked the whole codes, and placed inside a class called Main.as and refere this class inside <mx:Application>
      as following:

      <mx:Script source="Main.as" />

      I got the following error: 1037: Packages cannot be nested.

      Main class looks like this:
      package
      {
      import mx.rpc.remoting.RemoteObject;

      public class Main
      {
      private var currentUser:User;
      private var currentAccessTicket:AccessTicket;

      private var services:RemoteObject;


      public function Test()
      {
      services = new RemoteObject("GenericDestination");
      services.source="com.mydomain.Services";
      services.addEventListener(FaultEvent.FAULT, faultHandler);
      services.authorizeAccessTicket.addEventListener(ResultEvent.RESULT, loginResultHandler);
      .
      .
      .
      }
      }
      }

      What I have to do in this case?