A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Error 1131 - Nested classes?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    5

    Error 1131 - Nested classes?

    I've been trying to go through other forum posts and other websites trying to figure out how to fix this and so far I've had no luck. Here's my script thus far: (I'm using Flash CS5, AS3)
    Actionscript Code:
    import flash.events.MouseEvent;

    stop();

    Mouse.hide();
    stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
    function follow(evt:MouseEvent){
        gun_mc.x = mouseX;
        gun_mc.y = mouseY;
        }


        class zombieEnemy extends MovieClip
            {
            var speed;

            function onLoad()
            {
            _x = 875;
            _y = Math.random()*50 + 375;
                speed = Math.random()*5 + 5;
           
                velocity = 10;
                shootLimiter = 0;
                enemyTimer = 0;
           
                enemyTimer += 1;
                if(enemyTimer > 60)
       

            function onEnterFrame()
            {
                _x -= speed;
                if(_x < -100)
                {
                    this.removeMovieClip();
                }
            }

        {
        var velocity;
        var shootLimiter;
        var enemyTimer;

            enemyTimer += 1;
            if(enemyTimer > 60)
            {
                enemyTimer = 0;
                _root.attachMovie("zombieEnemy", "zombieEnemy"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
            }
        }
    }
        }

    I'm having issues with the class zombieEnemy. I honestly don't know where to start. What exactly do I need to do?

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    well firstly it looks like you're mixing AS3 and AS2 which is not going to work. Choose AS3. Secondly, I believe you need to define classes in external files, not on a timeline. So move your "ZombieEnemy" class code into a file called "ZombieEnemy.as". A Class in AS3 needs 3 components, its package, class name and constructor. The package is basically the path to your file, so if you place "ZombieEnemy.as" in the same directory as your fla, then the package is empty. However, if you placed the file in a sub directory named "classes" then the package would be "classes". The structure of your class should be this:

    Code:
    package {
    
    	public class ZombieEnemy extends MovieClip {
    	
    		private var speed:Number;
    		private var velocity:Number;
    		private var shootLimiter:Number;
    		private var enemyTimer:Number;
    	
    		public function ZombieEnemy() {
    		
    			//this is the constructor
    			
    			x = 875;
    			y = Math.random()*50 + 375;
    			speed = Math.random()*5 + 5;
    			velocity = 10;
    			shootLimiter = 0;
    			enemyTimer = 0;
    			
    			addEventListener(Event.ENTER_FRAME, onUpdate);
    		}
    		
    		private function onUpdate(event:Event):void {
    			
    			x -= speed;
    			
    			if (x < -100) {
    				
    				parent.removeChild(this);
    			}
    		}
    	}
    }
    Last edited by mr_malee; 10-26-2011 at 05:45 PM.
    lather yourself up with soap - soap arcade

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    5
    Ahh, that would be the issue with referring to different tutorials online lol

    but thank you for explaining it, I'll go through my code and hopefully get this working soon. I appreciate the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center