1 Reply Latest reply: Mar 28, 2012 11:11 PM by kglad RSS

    Error: Packages cannot be nested

    loreleila

      i have the following AS class file:

      package  {

       

                public class DropImage {

       

       

                          public function DropImage() {

       

                                     package{

       

       

      import flash.display.MovieClip;

      import flash.events.Event;

      import flash.net.URLLoader;

      import flash.net.URLRequest;

      import com.greensock.TweenNano;

      import com.greensock.easing.*;

       

       

      public class DropImage extends MovieClip {

       

       

        private var containerArray:Array = new Array  ;

        private var totalImgs:int = -1;

        private var counter:uint = 0;

        private var imageLength:uint;

       

       

        public function DropImage() {

         //Loads the xml

         var xmlLoader:URLLoader = new URLLoader  ;

         xmlLoader.load(new URLRequest("DropImages.xml"));

         xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);

        }

       

       

        //Creates new instances of the ImageContainer class with the y position

        //initally set off the stage and the rotation at -90. The -90 rotation

        //gives the dropping effect as the object gets tweened downwards.

        private function xmlLoaded(e:Event):void {

         var xml:XML = new XML(e.target.data);

       

       

         imageLength = xml.image.length();

       

       

         for (var i:int = 0; i < xml.image.length(); i++) {

          var imgc:ImageContainer = new ImageContainer(xml.image[i].attribute("src"));

          imgc.x = 100;

          imgc.y = -133;

          imgc.rotation = -90;

          imgc.alpha = 0;

          imgc.addEventListener("imageloaded",showImage);

          addChild(imgc);

          containerArray.push(imgc);

         }

        }

       

       

       

       

        //waits for all images before tweening

        private function showImage(e:Event):void {

         totalImgs++;

         if (totalImgs == imageLength - 1) {

          tweenBox();

         }

        }

       

       

       

       

        //tweens the images downwards to a randoms rotation between -11 and 11

        //and replays the tween after two seconds.

         private function tweenBox():void {

         

          TweenNano.to(containerArray[counter],1, {y:192.45,

               rotation:Math.floor(Math.random() * 11) - 11,

               alpha:1,

               ease:Sine.easeOut,

               onComplete:function(){

              if(counter != containerArray.length - 1){

               counter++;  

               TweenNano.delayedCall(2, tweenBox);

             }}

               });

        }

      }

      }

                          }}}

       

      It sais '1037: Packages cannot be nested' and if i click the error it goes to line 7 of the scrip..help please? 3

        • 1. Re: Error: Packages cannot be nested
          kglad MVP

          as3 Class files all follow the same general format listed below.

          1. package designation
          2. import statements
          3. the class declaration
          4. class-scoped (ie, not local to a function) variable declarations
          5. the class constructor
          6. other class functions

           

          p.s.  that's as3, not as1,as2.

          p.p.s.  format your code so it's legible.