A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: how do i put more than 1 class into a package?

  1. #1
    Member
    Join Date
    Mar 2004
    Posts
    45

    Question how do i put more than 1 class into a package?

    Every time I try to put more than one class into an external package I get an error at runtime:

    Code:
    5006: An ActionScript file can not have more than one externally visible definition: sampleBitmapTri, draggableClip
    Here is my code which is causing this:

    Code:
    package {
    
    	import flash.display.MovieClip;
    	import flash.events.MouseEvent;
    
    	public class draggableClip extends MovieClip {//drag a movieclip
    
    		public function draggableClip():void {
    			trace("draggableClip class constructor called!");
    		}
    
    		public function registerClip(MC):void {
    			trace("registering MC :"+MC.name);
    			MC.pointNumTXT.text = MC.name;
    			MC.addEventListener(MouseEvent.MOUSE_UP, thisMouseUp);
    			MC.addEventListener(MouseEvent.MOUSE_DOWN, thisMouseDown);
    		}
    
    		private function thisMouseDown(event: MouseEvent):void {
    			trace("clicked: "+event.target.name);
    			event.target.startDrag();
    		}
    
    		private function thisMouseUp(event: MouseEvent):void {
    			event.target.stopDrag();
    		}
    	}//drag a movieclip
    	
    	public class sampleBitmapTri {//sample a triangle from bitmapData
    
    		public function sampleBitmapTri():void {
    		}
    	}//sample a triangle from bitmapData
    	
    }
    I have read through an adobe article about this...but the explanation was not very clear to me.

    Could somebody please let me know what I'm doing wrong?

    Thanks in advance,
    David

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    each public class needs its own .as file. regardless if it's in the same package or not. You may have 100 files with the same package declaration. The only time more than one class may exist in one .as file is when you use a private "helper" class, but that must exist OUTSIDE the package {} declaration

  3. #3
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You can only have one public class. If you want to have more than one class you have to separate the classes but the next class will not be public.

    PHP Code:
    ...........
    private function 
    thisMouseUp (event:MouseEvent):void
            
    {
                
    event.target.stopDrag ();
            }
        }
    }
    class 
    sampleBitmapTri
    {

        public function 
    sampleBitmapTri ()
        {
        }

    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  4. #4
    5+5=55 Schfifty Five's Avatar
    Join Date
    Jun 2006
    Posts
    698
    You need to have a separate file for each (public) class.. so:

    In draggableClip.as:
    Code:
    package {
    
    	import flash.display.MovieClip;
    	import flash.events.MouseEvent;
    
    	public class draggableClip extends MovieClip {//drag a movieclip
    
    		public function draggableClip():void {
    			trace("draggableClip class constructor called!");
    		}
    
    		public function registerClip(MC):void {
    			trace("registering MC :"+MC.name);
    			MC.pointNumTXT.text = MC.name;
    			MC.addEventListener(MouseEvent.MOUSE_UP, thisMouseUp);
    			MC.addEventListener(MouseEvent.MOUSE_DOWN, thisMouseDown);
    		}
    
    		private function thisMouseDown(event: MouseEvent):void {
    			trace("clicked: "+event.target.name);
    			event.target.startDrag();
    		}
    
    		private function thisMouseUp(event: MouseEvent):void {
    			event.target.stopDrag();
    		}
    	}//drag a movieclip
    		
    }

    In sampleBitmapTri.as:
    Code:
    package {
    public class sampleBitmapTri {//sample a triangle from bitmapData
    
    		public function sampleBitmapTri():void {
    		}
    	}//sample a triangle from bitmapData
    }

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