6 Replies Latest reply on Aug 9, 2007 5:14 AM by Greg Dove

    force inclusion of imported classes

    dr_ross Level 1
      Hi guys,
      I'm having a bit of trouble getting classes referenced in the standard import manner to be forced to be included at runtime by the compiler, without making a token instance.

      i.e i want to force the inclusion of

      import Shapes.MyBox;

      so i can use it later on with a "getDefinitionByName" call instead of having to do a token "new MyBox()" somewhere in the code.

      Any ideas would be much appreciated
        • 1. Re: force inclusion of imported classes
          Greg Dove Level 4
          I don't know the 'correct' way to do this in as3, but in as2 I think all that is required is

          var forceMyBox:MyBox;

          It doesn't create an instance.

          e.g. if I did this, and nothing else
          var forceVideo:mx.video.VideoPlayer;

          Then the swf compiles with the as2 VideoPlayer class included.

          Perhaps you can do something similar with as3
          • 2. Re: force inclusion of imported classes
            dr_ross Level 1
            good idea but the trouble is i'm not actually declaring variables to typecast on. And there are dozens of classes i'd like to have included which won't be tied to indiviual variables.
            • 3. Re: force inclusion of imported classes
              Greg Dove Level 4
              Well I'm not sure if I have a good handle on how you want to do it ... is it not possible to create one class that just uses something like the above approach for all the classes you want to include?

              e.g. (again this works in as2)

              • 4. Re: force inclusion of imported classes
                Greg Dove Level 4
                Neither approach ties them to variables. In fact the variables are undefined. It just forces the compiler to include the class.
                • 5. Re: force inclusion of imported classes
                  dr_ross Level 1
                  i'm doing a sort of modifed version of that at the moment

                  import Tyriash.Enemies.*

                  then later

                  function declareTokenInstances()
                  {
                  new Enemy1();
                  new Enemy2();
                  new Enemy3() etc etc
                  then remove them
                  }

                  Its just its a bit of a ball ache having to write out all the references to dozens of
                  class,

                  i could do

                  private var enemy1:Enemy1
                  private var enemy2:Enemy2
                  etc etc but then these variables are declared and hanging around taking up memory and cpu time is needed to declare them.

                  All the instatiation is done on the fly using strings from XML then referenced to class definitions with "getDefinitionByName"

                  I'm sure there must be a way to say

                  force include import Game.Enemies.*
                  force include import Game.Weapons.*
                  etc etc
                  • 6. Re: force inclusion of imported classes
                    Greg Dove Level 4
                    I understand what you're looking for and yes... it would be very useful to have that approach.
                    I don't think it was there for as2. I don't know if it exists for as3. Let's hope someone else knows...