Reputation: 189
Say I have a class called DevilDog. This class DevilDog contains all the information that you need about a devilish dog except the animation and graphics. What is the best way to integrate a movieclip into the class DevilDog?
An example would be really helpful. I am unsure whether I will somehow be storing a movieclip in the same folder as DevilDog or using the central fla. file to export a movieclip for actionscript. Oh, and DevilDog will be contained in a separate folder than the fla. file
Thnx!
Upvotes: 1
Views: 37
Reputation: 7520
There are multiple ways to do so and there is no "best" practice. It all depends on your way of creating those files.
The common use would be that the DevilDog
class takes an "asset" parameter and keeps the graphical object inside a member variable. What this means is that the logic is separated from the graphic, and you can use the class with different graphics, just passing them as an argument when constructing.
This way you can do all your things beforehand - load assets, manipulate them in every way that you want, switch them if needed, etc. The example code would be similar to this:
public class DevilDog {
private var _graphic:Sprite; // could be MovieClip, Bitmap, whatever you have
public function DevilDog(graphic:Sprite) {
_graphic = graphic;
}
// OR
public function setGraphic(graphic:Sprite):void {
_graphic = graphic;
}
}
Common practice is that you set the graphic just a single time (maybe in constructor). This is done because not to run in an issue where there is a graphic instantiated and everything is working, and somehow from somewhere, a new graphic is set and it messes everything up.
So basically this is the most used practice and hopefully you could understand why. There are other ways but this works almost always :)
Upvotes: 1