Support NATA 2014

swc class has same name as src clas

  • 311 Views
  • 5 Replies
New Topic Respond to this Topic
Rational-Delirium
Rational-Delirium
  • Member since: Mar. 21, 2007
  • Offline.
Forum Stats
Supporter
Level 15
Melancholy
swc class has same name as src clas Dec. 28th, 2012 @ 11:55 PM Reply

I'm new to AS3, and I'm trying to learn SWC files, but it's really outside my comfort zone. When I compile my SCW and add it to the library in FlashDevelop, everything works fine, namely, the name of the SWC file turns blue. The problem is that the classes which are associated with the symbols in the SWC library, have the exact same name as the classes that are in the SRC folder.

Here's a picture for example. I have two classes called Enemy.as. Main can't refer to the one in the swc folder, because the one in the lib folder has dominance. Yet I can't delete the one in the lib folder because the FLA automatically generates it upon compiling the SWC.

swc class has same name as src clas


You can't know what you don't know if you can only use yourself as a reference point.

Rational-Delirium
Rational-Delirium
  • Member since: Mar. 21, 2007
  • Offline.
Forum Stats
Supporter
Level 15
Melancholy
Response to swc class has same name as src clas Dec. 28th, 2012 @ 11:58 PM Reply

At 12/28/12 11:55 PM, Rational-Delirium wrote: Here's a picture for example. I have two classes called Enemy.as. Main can't refer to the one in the swc folder..

I meant to say "Main can't refer to the one in the src folder.."


You can't know what you don't know if you can only use yourself as a reference point.

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to swc class has same name as src clas Dec. 29th, 2012 @ 01:06 AM Reply

Yeah, that's how swcs work, they create classes to be used as assets. The way I avoid this is I start every name in my swc with "Swc" so it'd be "SwcEnemy" and "SwcAvatar" to make sure there are no reference errors.

What you could also do is put them in folders and specify which by package name.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
Rational-Delirium
Rational-Delirium
  • Member since: Mar. 21, 2007
  • Offline.
Forum Stats
Supporter
Level 15
Melancholy
Response to swc class has same name as src clas Dec. 29th, 2012 @ 02:23 AM Reply

At 12/29/12 01:06 AM, MintPaw wrote: Yeah, that's how swcs work, they create classes to be used as assets. The way I avoid this is I start every name in my swc with "Swc" so it'd be "SwcEnemy" and "SwcAvatar" to make sure there are no reference errors.

What you could also do is put them in folders and specify which by package name.

Thanks, that worked a lot :)
Here's the code encase someones curious on how to get Main to initialize an 'Enemy' class which extends a 'SwcEnemy' class which extends a Sprite class.
Main:

package {
	import Classes.Enemy;
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class Main extends Sprite {
		public var enemy:SwcEnemy;
		
		public function Main():void {
			enemy = new Enemy();
			addChild(enemy);
			
		}
	}
}
package Classes {

	public class Enemy extends SwcEnemy {
		
		public function Enemy() {
			x = 100;
			y = 100;
		}
	}
}

You can't know what you don't know if you can only use yourself as a reference point.

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to swc class has same name as src clas Dec. 29th, 2012 @ 03:35 AM Reply

That's a way to do it, but I tend to use this method, only using the swc as a graphic.

package Game 
{
	/**
	 * ...
	 * @author MintPaw
	 */
	public class Box extends Sprite
	{
		var _swc:SwcBox = new SwcBox();

		public function Box() 
		{
			addChild(_swc);
		}
	}
}

Then you just create new Box's and the graphic comes attached to it.
It's a concept called inheritance vs composition, if you can chose not to extend something, and rather just make the object composed of said other object then you probably should. Since each object can only extend one thing it's probably good not to waste it on the graphic. Using this method Box is free to inherit things like GameObject or anything thing else.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to swc class has same name as src clas Dec. 29th, 2012 @ 01:24 PM Reply

yes, packages are used to separate different classes. You can have class "Enemy" in package "example1" and one in "example2" - you can also import and use them both.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature