4 Replies Latest reply on Oct 16, 2008 8:40 AM by jeffreypritchard

    accessing local namespace classes from AS3

    jeffreypritchard
      Hi,

      I'm trying to create a little browser application that will allow me to select one of my symbols and add it to the screen. The class associated with the component is in the local namespace (xmlns:local-"*"). I can add the components through mxml with no problem, but when I try to add it through actionscript, the compiler says that the class is not defined when I use getClassDefinitionByName(className) as Class.

      Why is it that I can use <local:className> to add it but I can't use var:symbolName:className = new className()?

      I looked at the 'use namespace...' documentation, but a) I don't know where to define my class as being part of a namespace, and b) how do I access it through actionscript ( is it local::className ???).

      Thanks in advance.


        • 1. Re: accessing local namespace classes from AS3
          Level 7

          "jkpritchard" <webforumsuser@macromedia.com> wrote in message
          news:gd2c0e$rlj$1@forums.macromedia.com...
          > Hi,
          >
          > I'm trying to create a little browser application that will allow me to
          > select
          > one of my symbols and add it to the screen. The class associated with the
          > component is in the local namespace (xmlns:local-"*"). I can add the
          > components
          > through mxml with no problem, but when I try to add it through
          > actionscript,
          > the compiler says that the class is not defined when I use
          > getClassDefinitionByName(className) as Class.
          >
          > Why is it that I can use <local:className> to add it but I can't use
          > var:symbolName:className = new className()?
          >

          try:

          new classN

          then press and hold the control key and press the space bar. If there is
          more than one class that shows up, use the mouse to select your class, then
          press enter. You will find that this will make the proper import for you.
          However, if the class is at the root of your src folder, it shouldn't need
          to be imported, in which case I'm not sure.

          HTH;

          Amy


          • 2. Re: accessing local namespace classes from AS3
            Peter Lorent Level 2
            >>The class associated with the component is in the local namespace (xmlns:local-"*").
            What class do you mean here?
            • 3. Re: accessing local namespace classes from AS3
              ntsiii Level 3
              Be careful not to confuse XML namespace with Package namespace. the Namespace class and the double colon syntax are for XML namspace only.

              Import, package declaration and xmlns are all package namespace oriented.

              I assume this is a typo: xmlns:local-"*").

              Also be aware that when using getClassDefinitionByName, you must have a hard reference to that class declared somewhere in your app, or the class will not get linked in by the compiler. A dummmy variable is often used.

              Finally, I don't use a prefix for local classes, just xmlns="*". Perhaps doing so makes you explicitly use local like this?
              var symbolName:className = new local.className()
              Truly just guessing on this one.

              Tracy
              • 4. Re: accessing local namespace classes from AS3
                jeffreypritchard Level 1
                Thanks for the help. I think I did exactly what Tracy was talking about and thought that the xml namespace and the package namespace were the same thing.

                I had my packaged code outside the src folder (in lib), so none of it could be located (which I know now could have worked if i set the reference correctly in the project).

                Everything has been moved to the src folder (including the package structure), and everything is working fine now.

                After using Flex Builder for only a couple of weeks, I have to say I love the IDE. Code completion for custom classes is such a great thing that the Flash IDE never could do.

                Thanks very much to everyone who responded.