Strike Force Heroes 2
The explosive sequel to the hit game Strike Force Heroes!
3.95 / 5.00 11,184 ViewsObsolescence
Defeat the enormous mechanical beasts--and become one of them.
4.03 / 5.00 49,432 ViewsI'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.
If you need a preloader, and don't know how to stop your movie from looping, come here :)
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.."
If you need a preloader, and don't know how to stop your movie from looping, come here :)
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.
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;
}
}
} If you need a preloader, and don't know how to stop your movie from looping, come here :)
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.
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