A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Classes?

  1. #1
    It's not 1997 ?! mrgrim333's Avatar
    Join Date
    Feb 2004
    Posts
    254

    Question Classes?

    How would I got about setting up classes in as2?
    I've used them in c++, but never flash.

    I want to have like:
    Code:
    class plants
    {
    public:
      int number;
      int age;
      int water;
    };
    then use it like:
    Code:
    plant 1;
    1.number = 5;
    1.age = 100;
    1.water = 50;
    Man, I need a new signature.

  2. #2
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361

  3. #3
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    AS3:

    class
    Code:
    package
    { //your class goes in a package definition, 1 class per package, but you can define helper classes outside the package bounds
    
    //import flash.display.*; is similar to #include is c++
     public class plants
      {
        public var 
        nmber:int,
        age:int,
        water:int; //you might wanna define a constructor here to initialize those vars
      }
    }
    usage
    Code:
    var p1 =  new plants();
    p1.number = 5;
    p1.age = 100;
    p1.water = 50;
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  4. #4
    Funkalicious TOdorus's Avatar
    Join Date
    Nov 2006
    Location
    Nijmegen, Netherlands
    Posts
    697
    Quote Originally Posted by bluemagica View Post
    1 class per package
    This is false. It is only one class per file. Say your document class is in a file called D:\MyGame\bin\DocumentClass.as and your swf will be created in D:\MyGame. The package of DocumentClass.as is than bin, as the swf's location will be treated as a root.

    D:\MyGame\bin\DocumentClass.as
    Code:
    package bin
    {
    	public class DocumentClass extends MovieClip
    	{
    		
    		public function DocumentClass():void 
    		{
    			//
    		}
    	}
    }
    Now say I have a physics package with all my physics functions. I'll have to store it in it's own folder (every package needs it's own folder). Say it contains a rigidbody class and a collisiondetection class. It is located in D:\MyGame\bin\Physics

    D:\MyGame\bin\Physics\rigidBody.as
    Code:
    package bin.Physics
    {
    	public class rigidBody
    	{
    		
    		public function rigidBody():void 
    		{
    			//
    		}
    	}
    }
    D:\MyGame\bin\Physics\collisionDetection.as
    Code:
    package bin.Physics
    {
    	public class collisionDetection
    	{
    		
    		public function collisionDetection():void 
    		{
    			//
    		}
    	}
    }
    If you wish to import something in a class the file holding the class is considered root. So if you'd wish to import collisionDetection into the DocumentClass you'd use import Physics.collisionDetection. If you would wish to import the rigidBody into the collisionDetection class you'd simply use import rigidBody.

    You may want to look up acces-control modifiers in that case too bluemagica.

  5. #5
    Custom User Title Incrue's Avatar
    Join Date
    Feb 2004
    Posts
    973
    //your class goes in a package definition, 1 class per package, but you can define helper classes outside the package bounds
    I usually do the same, but, you can have more than one class with the same package and thats the point, classes that are somehow related can all be organized and imported at the same time

  6. #6
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    I normally use something along the lines of:

    Code:
    com
       hsg
          Application.as // launched after preload in Doc class
          doc
             DocumentClass.as
          ui
             HUD.as
             // additional custom display object classes here
          util
             // helper classes here
    so the packages would be something like...

    • com
    • com.hsg
    • com.hsg.Application
    • com.hsg.doc.DocumentClass
    • com.hsg.ui.HUD
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

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