1 Reply Latest reply on Mar 21, 2008 6:25 PM by levancho

    Package level definitions, need clarification

      I'm new to Flex and ActionScript and I'm having some difficultly understanding when/what definitions are allowed at the package level. I'm currently using Flex 3.0 and doing my development via Adobe's handy Flex Builder Eclipse plug-in. If I understand the ActionScript spec correctly, defining functions, variables, and constants at the package level is allowed:

      package mypacakge {
      public const SOME_CONSTANT:String = "A Constant";
      public function someFunction( ) : void {

      Now when building a Flex app, it appears that the only ActionScript code that can be included and used is that defined in either a class AS file - an AS file which may only contain a single package level public class definition, no package level functions, variables, constants, and all other class definitions may not be public - or just a normal AS file. It would seem that the normal use of a regular AS file in flex would be for its inclusion in an MXML file, such as:

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

      When used in such a way, an AS file may not contain a package definition or else an infamous "1037: Packages cannot be nested." error is given. So what is the use case in Flex for having package level function and variable definitions and how would one take advantage of such an ability? Also, if such is simply not feasible, what is the the general convention for defining constants and utility functions for an application? Is the same standard used in Java applied in Flex of having a class called Constants hold all the application/library constants and utility classes to hold generally available static utility functions (like the pow, acos, etc functions in Java's Math class)?

      Thanks for your help,
      - John