1

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!

theseal53
  • 189
  • 10

1 Answers1

1

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 :)

Andrey Popov
  • 7,362
  • 4
  • 38
  • 58
  • The setter approach is better I think. Being able to switch out the skin at run time is pretty powerful. It means you could have a much more generic base class for the characters (assuming they share behaviours), and supply them different skins for the way they look. – net.uk.sweet Jun 12 '14 at 09:54
  • Well that's why I said it's a common practice - for all of those that don't truly know how to do it. If you master dependency injection and handling it properly - it's a great approach! I just didn't want him to bother too much about handling new graphic at runtime. Anyways good point! :) – Andrey Popov Jun 12 '14 at 09:56
  • thnx for your responses, guys! very helpful :) – theseal53 Aug 10 '14 at 05:40