A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: [SHARE] Donate a Class!

  1. #1
    Trainee coder Viza's Avatar
    Join Date
    Sep 2006
    Location
    Melbourne, Down under
    Posts
    513

    [SHARE] Donate a Class!

    After writing a couple of new classes, I noticed how weak my small library of classes is. I figured maybe we could start a collection of classes for anyone here to use.

    So here's one of my very early classes. This arrow class acts like a bullet but is affected by gravity and rotates towards the ground accordingly.
    It's super basic, but does the job nicely I'd like to think - it should be a nice addition to anyone just starting to build up on their library.

    If anyone's willing to share a class or two, I think we could get a pretty sweet FK collection happening. It doesn't matter how easy or complicated the class is; if you think someone will find it handy then upload it.

    Viza.

    P.S. Sorry about my bad coding habits and lack of OO principles. Hopefully after seeing some 'proper' OOP from anyone else's classes I'll be able to improve.
    Attached Files Attached Files

  2. #2
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    What a great idea ( An even better one would be to set up a svn somewhere to put all these ).

    I've attached my soundClass, which has been making beeps beep easily for quite a while ( I think it was first coded for Polarity, and has managed to see me through to Landfill of Doom without any major updates ).

    The one really nice method in there is createPlayAndDispose() which is just a really simple way to trigger those one off sounds, for when you're feeling lazy or rushing to get something done.

    I've attached it as a txt file 'cause of the nature of the board, and as a caveat it's as2 ( I need to port all these old library classes to as3. Joy ).

    Squize.
    Attached Files Attached Files

  3. #3
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    I have heaps of little classes, but none which have helped me more than this one. It exists in every project I have done since I started working.

    AS3
    Last edited by mr_malee; 07-16-2008 at 10:17 AM.
    lather yourself up with soap - soap arcade

  4. #4
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425
    Great idea, Viza!
    This is the class I've reused the most, BitmapScroller. Only thing that
    kind of sucks is that it requires a 2d array for the map, but this could
    easily be changed.
    Attached Files Attached Files
    // Mazapán, my portfolio

  5. #5
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180
    Edit: Ok screw CodePlex.

    But an SVN would be awesome though.
    Last edited by SaphuA; 04-18-2008 at 08:55 AM.

  6. #6
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    I think to go along with these classes are examples which demonstrate their use and how to use them. This would especially help beginner coders.
    now known as dVyper

  7. #7
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Great plan, except for the version control.

    I can download, save and update files without a special piece of software doing it for me at one tenth of the speed.

  8. #8
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    Here's a modest polygon class that supports clipping to an arbitrary convex window using the Sutherland-Hodgman algorithm. It also can compute the convex hull of a set of polygons using the gift-wrapping algorithm (Jarvis march). There's an example driver program too.
    Attached Files Attached Files

  9. #9
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180
    Lesli, SVN is not an FTP server. The features that SVN offers are very interesting for these kind of projects. Especially when things get bigger and you loose track of everything.

    Maybe someone could set up an SVN on sourceforge or GoogleCode (is it GoogleCode? I dunno).

    I was thinking of organizing it somehow like this:
    flashclasslibrary.as2.etc
    flashclasslibrary.as3.etc
    flashclasslibrary.testbed.as2.etc
    flashclasslibrary.testbed.as3.etc


    ~Sph

  10. #10
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    I've used SVN. I know what it can do. It's horrible.

    It's taken me a whole morning to rename a folder using svn, and I've lost work that didn't get put in the recycle bin (svn doesn't put anything there because it thinks it's clever enough to stop you from losing your work... even work it tries to delete from your system that you haven't checked in)

    Sure, I can roll back my work to seven versions previous. But there's no need because of all the copies I've saved outside of svn because the svn server kept crashing or a designer wanted to review my work and didn't know what version control was.

    Of course, svn does allow two coders to edit a class at the same time and merge their updates into one class file that doesn't work any more. Useful for making projects go on for longer and charging the client more.

    Sorry, bad subject for me I'm afraid..........

  11. #11
    Trainee coder Viza's Avatar
    Join Date
    Sep 2006
    Location
    Melbourne, Down under
    Posts
    513
    Hmmm... Seems like not many have the sharing spirit.

    Here's a Ball class. You could use this for all sorts of things ( mainly ball-on-ball collisions). Attached in the .zip file is a fully commented class, .fla file containing temp gfx, and also demonstration code to get something working instantly.

    I'd like to take credit for all of the smart things in that class, but unfortunately this clas was mainly written by someone else and I've just made personal adjustments and small function additions. I'm sure he wouldn't mind me sharing this, since I obtained it through his blog which was freely distributing it anyway.

    Viza.
    Attached Files Attached Files

  12. #12
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    While I think this is a great idea, Viza, I don't have any classes that aren't custom for the content I'm using them for. Not too many of the classes I've wrote have been reusable.
    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

  13. #13
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    I've had some bad times with svn too ( Makes it sound like it touched me when it was drunk, and was then all apologetic in the morning ).

    But for something like this I think it's pretty ideal. We've recently set up a repository for gyw where Olli and I are going through the hell of porting existing code to as3 ( We're trying to avoid re-inventing the wheel. Twice over ).
    To just share common code it's pretty good, it's just when you're doing a huge project with it it's a mare and easy to really badly mess things up.

    Also, this thread is a bit lacking in content. No one else wanting to share ? Surely after all the recent as3 advocates around here, loving the oop'ness of it, there should be a ton more general classes out there which are easy to re-purpose.

    Squize.

  14. #14
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Y'see this is the thing, I've got loads of code snippets and functions I re-use. About half mine, half not, few of which are game related. The ones that are game related are real simple (shuffle an array, get distance between points etc)

    That said, I'm working on a RecordedObject Class, which simply takes the MovieClip class and makes it east to store all of its properties per frame so it can be rewound, played back etc. A RecordedScene class will handle the whole thing and store information and govern playback controls.

    If I ever finish it and put it to use, I'll post it here.

    This thread, or one like it, without all the ranting, would be ideal for a sticky, as it'll take a while for people to post to it, and people will need to come back to it over again.

  15. #15
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Quote Originally Posted by Squize
    Also, this thread is a bit lacking in content. No one else wanting to share ? Surely after all the recent as3 advocates around here, loving the oop'ness of it, there should be a ton more general classes out there which are easy to re-purpose.

    Squize.
    I've got a couple of useful classes, but they're usually more of a package than a stand alone class. My scrolling engine is 8 classes right now, and even though it's very useuable, it's not finished. Same with my platform engine, or my tweening stuff, or my (now a bit dated) pathfinder. (EDIT: sounds like I'm bragging with my stuff, but just wanted to say that while I want to share something useful, I don't have many single classes that are useable without context, and most of my stuff is designed for eachother).

    But just because I want to share something, here is my Key class. It uses the same mechanim as Senocular's class, but fixes a weird problem when the keys suddenly stopped working after removing an event listener somewhere else. There's still a problem with the contextual menu, if anyone knows how to fix that...


    PHP Code:
    package com.crossconscious {
        
    import flash.display.Stage;
        
    import flash.events.ContextMenuEvent;
        
    import flash.events.Event;
        
    import flash.events.EventDispatcher;
        
    import flash.events.KeyboardEvent;
        
        
    /**
        * ...
        * @author Sven Magnus
        */
        
    public class Key {
            
            public static var 
    stage:Stage;
            private static var 
    keys:Object = { };
            
            public static function 
    init(stage:Stage):void {
                
    Key.stage stage;
                
    stage.addEventListener(KeyboardEvent.KEY_UPKey.keyUp);
                
    stage.addEventListener(KeyboardEvent.KEY_DOWNKey.keyDown);
                
    stage.addEventListener(Event.DEACTIVATEKey.clear);
            }
            
            public static function 
    addEventListener(type:String,func:Function):void {
                
    Key.stage.addEventListener(typefuncfalse0true);
            }
            
            public static function 
    removeEventListener(type:Stringfunc:Function):void {
                
    Key.stage.focus Key.stage;
                
    Key.stage.removeEventListener(typefunc);
            }
            
            private static function 
    keyUp(e:KeyboardEvent):void {
                if (
    e.keyCode in Key.keys) {
                    
    delete Key.keys[e.keyCode];
                }
            }
            
            private static function 
    keyDown(e:KeyboardEvent):void {
                
    Key.keys[e.keyCode] = true;
            }
            
            public static function 
    isDown(keyCode:int):Boolean {
                if (
    Key.keys[keyCode]) return true;
                return 
    false;
            }
            
            private static function 
    clear(e:Event):void {
                
    Key.keys = { };
            }
            
        }
        

    Last edited by Fall_X; 04-21-2008 at 06:58 PM.

  16. #16
    The Cheeze to Your Macaroni ColbyCheeze's Avatar
    Join Date
    Dec 2007
    Location
    Texas
    Posts
    244
    I have posted about these but since this thread is dedicated to this stuff I'll mention it here:

    The following links have the downloads on them as well as instructions on how to use them...

    My Animated BitmapClip class:
    http://cheezeworld.com/game-library/bitmapclip/

    Complete Input / Keycode classes:
    http://cheezeworld.com/tutorials/custom-input-class/

  17. #17
    Senior Member The Helmsman's Avatar
    Join Date
    Aug 2005
    Location
    _root
    Posts
    449
    Here are my two cents:
    Code:
    /**
    * Debug
    * -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    * @author Igor Vasiliev aka The Helmsman
    * @version 0.3
    * 	to setup debug sections
    * @usage var myDebug:Debug = new Debug(new Array(["system manager", "off", 1]), output_txt);
    * 	to initialize
    * @usage myDebug.initDebug();
    * 	to print message
    * @usage Debug.printMsg("Hello world", 1);
    *
    * DESCRIPTION:
    * -=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    * Debug module responsible for printing debug messages to pre-defined output text field area.
    */
    
    package utils {
    	
    	import flash.text.TextField;
    	import flash.utils.setInterval;
    	
    	public class Debug {
    
    		//	-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    		//	public properties
    		//	-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    
    		//	-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    		//	private properties
    		//	-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    		
    		private var iid:int;										//	queue check id
    		private var queCheckInterval:int = 1000;					//	queue check interval
    		
    		private static var msgQue:Array;							//	stores debug messages
    		private static var isInitialized:Boolean = false;			//	init flag - if initialized: start check queue
    		
    		private var debugArray:Array = new Array();					//	stores debug settings
    		private var output:TextField;								//	text field to represent debug messages
    		private var lineCnt:Number;									//	line counter
    
    		//	-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    		//	public methods
    		//	-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    
    		/**
    		* Debug class constructor
    		* @param	debugArray	- debug array with initial settings
    		* @param	output		- reference to a text field used for debug output
    		*/
    		public function Debug(debugArray:Array, output:TextField) {
    			
    			this.lineCnt = 0;										//	reset line counter
    			this.output = output;									//	save reference to output text field
    			this.debugArray = debugArray;							//	save debud settings data
    		}
    		
    		/**
    		* Initialize debug module to start queue processing
    		*/
    		public function initDebug():void {
    			
    			msgQue = new Array();									//	reset messages queue
    			isInitialized = true;									//	update initialization flag
    			
    			var obj:Object = {msg:"Debug is initialized", lvl:0};	//	create new message
    			msgQue.push(obj);										//	add message to queue
    			
    			iid = setInterval(queProcessing, queCheckInterval);		//	start processing
    		}
    		
    		/**
    		* Save incoming messages in queue for future print
    		* @param	msg - string contains message
    		* @param	lvl - number represents section of code
    		*/
    		public static function printMsg(msg:String, lvl:Number):void {
    			
    			if(!isInitialized) return;								//	check initialization flag
    			var obj:Object = {msg:msg, lvl:lvl};					//	create new message
    			msgQue.push(obj);										//	add message to queue
    		}
    		
    		//	-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    		//	private methods
    		//	-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-
    		
    		/**
    		* prints trace messages according to the output settings
    		*/
    		private function queProcessing():void {
    
    			if(msgQue.length == 0) return;							//	check for new messages
    			
    			for(var i:int=0; i<msgQue.length; i++) {
    				for(var j:int=0; j<debugArray.length; j++) {
    					if(debugArray[j][2] == msgQue[0].lvl && debugArray[j][1].toString() == "on") {
    						lineCnt++;									//	update line counter
    						//	show debug message in output textfield
    						if(lineCnt == 1) {							//	first message
    							//output.htmlText = "<font color='#990099'>"+lineCnt+" "+debugArray[j][0]+" -> </font>"+msgQue[0].msg+"\n";
    							output.text = lineCnt+" "+debugArray[j][0]+" -> "+msgQue[0].msg+"\n";
    						} else {
    							//output.htmlText += "<font color='#990099'>"+lineCnt+" "+debugArray[j][0]+" -> </font>"+msgQue[0].msg+"\n";
    							output.appendText(lineCnt+" "+debugArray[j][0]+" -> "+msgQue[0].msg+"\n");
    						}
    						output.scrollV += output.maxScrollV;		//	scroll up
    						
    					}
    				}
    				msgQue.shift();										//	remove message from queue
    			}
    		}
    	}
    }
    This code I use in every project during last three years (now it is written in AS 3.0). The purpose of this class to debug different parts of Flash application simply by changing initial settings of debug array.
    For example, you have three classes in your project:
    - ApplicationManager.as
    - Clock.as
    - ClockRepresentator.as

    The initial settings of Debug array can be:
    Code:
    var myDebug:Debug = new Debug(new Array(["ApplicationManager", "off", 1],
    ["Clock", "off", 2], ["ClockRepresentator", "off", 3]), output_txt);
    Then you need to add following code to each class where you want to use Debug module:
    Code:
    import utils.Debug;
    private function pm(msg:String):void {
    Debug.printMsg(msg, $N);
    }
    where $N must be 1, 2 or 3 depending on class where it is used.
    Now when you need to print something inside the class, you must use pm("your message"); instead of trace("your message"); and it will be seen on the output text area (in case when you set print option to "on").

    The code can be easily modified to use with different Flash debug plug-ins available today (for example Flash Tracer + Flash Player debug version).

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