[AS3] Collaberative Coding

Well, I suppose this falls under the ‘Experiment’ category. If it’s in the wrong place… feel free to move it.

This forum game originated from the old old bit-101 lab forums and we used as2, and it was tons of fun over there… Never tried it with as3… hope you like it though.

Basically, we start with a base Actionscript code, and each new post, someone gets to add or modify a line of code. Hopefully, after a while we will have something cool (and probably very random too!).

Rules (READ THEM ALL PLEASE BEFORE CONTRIBUTING):
[LIST=1]
[]**When you reply to this thread, you get to modify or add [COLOR=Red]ONE[/COLOR] line of code.
[
]If you wish, you can define a new function or class, but that counts as your one line, no putting anything in it in the same turn.
[
]No inline if statements or other hacky code
[
]No hugely long lines (more than 80 characters or so), keep your lines small and clean, and don’t use too many operations or functions.
[]Adding the required import statements does not constitute as a line.
[
]Must compile with the flex SDK, as a Flash 9 document class or equivalent. Please CHECK your code before posting it.
[]You may only import packages in the flash. namespace. No mx.* or anything else.
[]The dimensions are 550x400, the framerate is 30fps. The background color is WHITE.
[
]No [EMBED] directives (or whatever they’re called!)
[]If you add an eventListener, you may (must!) add the corresponding function so that the code compiles correctly…
[
]All code must be contained in one ‘file’… no adding separate codes which must be contained in a separate file.
[]Please, in your post, describe what you changed or added!
[
]You may (and should) include comments (maybe explaining what you are trying to do or want the next person to do?)
[/LIST]

note, I constructed and tested this with the flex 3 sdk compiling with FlashDevelop. Let me know if it needs to be modified to compile with other tools.

Popular things to use are the drawing API, bitmap data, and easy simple things like that.

Here is the starting code:


package 
{
        import flash.display.Sprite;
        import flash.events.Event;
    
        public class Main extends Sprite
        {
        
                public var thing:Sprite = new Sprite();
        
                // NOTICE: YOU MAY NEED THIS, OPTIONAL
                // [SWF(backgroundColor="#FFFFFF", frameRate="30", width="550", height="400")]
                public function Main():void
                {
            addChild(thing);
                        addEventListener(Event.ENTER_FRAME, Update);
                }
        
                public function Update(evt:Event):void {
            
                }
        }
}

I will periodically compile it and post the current swf.
Now the next person adds a line, and the next, etc… Go!

Hey Jonanin! I think our “thing” needs a class of its own, how about if we set also a basic class for it?

Go ahead…

Maybe something like this would do the trick:

Thing.as



package  {

	import flash.display.Sprite;
	import flash.events.Event;	
	 
	public class Thing extends Sprite {
		
		private var _life:int = 100;
		
		
		public function Thing(){
			                                                 
		}
		

	}                       
}


Erm, no adding new files… that makes things too hard to keep track of and compile. You must keep it to the main source.
Also, you may only add the class declaration, nothing inside of it, because function/class decl. constitutes one line.
But if you insist on a new class for it:

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class Main extends Sprite
    {
        
        public var thing:Sprite = new Sprite();
        
        // NOTICE: YOU MAY NEED THIS, OPTIONAL
        // [SWF(backgroundColor="#FFFFFF", frameRate="30", width="550", height="400")]
        public function Main():void
        {
            addChild(thing);
            addEventListener(Event.ENTER_FRAME, Update);
        }
        
        public function Update(evt:Event):void {
            
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;

class Thing extends Sprite {
    
    public function Thing() {
    
    }
}

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    
    public class Main extends Sprite
    {
        
        public var thing:Sprite = new Sprite();
        
        // NOTICE: YOU MAY NEED THIS, OPTIONAL
        // [SWF(backgroundColor="#FFFFFF", frameRate="30", width="550", height="400")]
        public function Main():void
        {
            addChild(thing);
            addEventListener(Event.ENTER_FRAME, Update);
        }
        
        public function Update(evt:Event):void {
            
        }
    }
    

    
}

import flash.display.Sprite;
import flash.events.Event;


class Thing extends Sprite {
    
    private var life:int = 100;   
    private var occupation:String;
    
    public function Thing() {
    
    }
}  

added “occupation” as a property of thing, and took away the underscore from life, simply because i havent seen an underscore since as2 :smiley:

Added a “DrawMe” function

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    
    public class Main extends Sprite
    {
        
        public var thing:Sprite = new Sprite();
        
        // NOTICE: YOU MAY NEED THIS, OPTIONAL
        // [SWF(backgroundColor="#FFFFFF", frameRate="30", width="550", height="400")]
        public function Main():void
        {
            addChild(thing);
            addEventListener(Event.ENTER_FRAME, Update);
        }
        
        public function Update(evt:Event):void {
            
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;

class Thing extends Sprite {
    
    private var life:int = 100;   
    private var occupation:String;
    
    public function Thing() {
    
    }
    public function DrawMe():void {
    }
}  

@theonlycarmire: I use underscores for private variables that shouldn’t be accessible from other classes. But if you prefer the contrary it’s the same for me :slight_smile:


package
{
    import flash.display.Sprite;
    import flash.events.Event;

    
    public class Main extends Sprite
    {
        
        public var thing:Sprite = new Sprite();
        
        // NOTICE: YOU MAY NEED THIS, OPTIONAL
        // [SWF(backgroundColor="#FFFFFF", frameRate="30", width="550", height="400")]
        public function Main():void
        {
            addChild(thing);
            addEventListener(Event.ENTER_FRAME, Update);
        }
        
        public function Update(evt:Event):void {
            
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;

class Thing extends Sprite {
    
    private var life:int = 100;   
    private var occupation:String;
    
    public function set _occupation(value:String) {
   occupation=value;
}

    public function Thing() {
    
    }
    public function DrawMe():void {

}
}  

added a setter function

Sorry magcius, you can only add ONE line of code. Only one statement per line, also. And you totally edited the other people’s additions
I’ll only include your g.clear() statement. Why use g:Graphics? Thing extends sprite… just use it’s graphics.

I’ve added a beginFill() (like magcius’)

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    
    public class Main extends Sprite
    {
        
        public var thing:Thing = new Thing();
        
        // NOTICE: YOU MAY NEED THIS, OPTIONAL
        // [SWF(backgroundColor="#FFFFFF", frameRate="30", width="550", height="400")]
        public function Main():void
        {
            addChild(thing);
            // maybe make a whole array of things?
            addEventListener(Event.ENTER_FRAME, Update);
        }
        
        public function Update(evt:Event):void {
            // TODO: be implemented.
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;

class Thing extends Sprite {
    
    private var _life:int = 100;   
    private var _occupation:String;
    
    // hopefully set the thing's position to something other than 0,0
    
    public function Thing():void {
        DrawMe();
    }
    
    public function DrawMe():void {
        this.graphics.clear();
        this.graphics.beginFill(0);
    }
    
    public function set occupation(value:String):void 
    {
        _occupation = value;
    }

} 

sounds like fun :slight_smile:

I added a drawroundrect:


package
{
    import flash.display.Sprite;
    import flash.events.Event;

    
    public class Main extends Sprite
    {
        
        public var thing:Thing = new Thing();
        
        // NOTICE: YOU MAY NEED THIS, OPTIONAL
        // [SWF(backgroundColor="#FFFFFF", frameRate="30", width="550", height="400")]
        public function Main():void
        {
            addChild(thing);
            // maybe make a whole array of things?
            addEventListener(Event.ENTER_FRAME, Update);
        }
        
        public function Update(evt:Event):void {
            // TODO: be implemented.
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;

class Thing extends Sprite {
    
    private var _life:int = 100;   
    private var _occupation:String;
    
    // hopefully set the thing's position to something other than 0,0
    
    public function Thing():void {
        DrawMe();
    }
    
    public function DrawMe():void {
        this.graphics.clear();
        this.graphics.beginFill(0);
        this.graphics.drawRoundRect(-40,-25,80,50,5,5);
    }
    
    public function set occupation(value:String):void 
    {
        _occupation = value;
    }

}