JCR10
JCR10

Reputation: 79

multiple movieclips and one class linkage ActionScript 3

MovieClip Aries has a "AS Linkage" class of Aries. MovieClip Zeus has a "AS Linkage" class of Zeus. MovieClip Maze Runner has a "AS Linkage" class of MazeRunner. and a Hero class.

MazeRunner class adds hero into stage.

package
{   
    public class MazeRunner extends MovieClip
    {
        private var _hero           :Hero;

        public function MazeRunner():void
        {
            if(stage == null)
            {
                addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
                addEventListener(Event.REMOVED_FROM_STAGE, clean, false, 0, true);
            }
            else
            {
                init();
            }
        }

        private function init(e:Event = null):void
        {
            _hero = new Hero;
            addChild(_hero);
        }
    }
}

I want "Hero" class to be connected/associated to both "Aries" or "Zeus" MovieClip class so that either movieclips can be added on the stage when i choose between them before MazeRunner add it to the stage. is that possible?

Upvotes: 0

Views: 207

Answers (1)

Peter B
Peter B

Reputation: 142

I would suggest passing a parameter when instantiating your hero class.

For example:

_hero = new Hero("Zeus");

And then in your Hero class, you'd just have to instantiate a movieclip using a switch statement:

switch (selectedCharacter){

case "Zeus":
_hero.addChild(Zeus);
break;

case "Aries":
_hero.addChild(Aries); 
break;
} 

Sorry, I'm a bit rusty with as3. I assume Zeus or Aries will contain the images/properties of that character. This will, in theory, attach your character to the _hero movieclip. You can then have access to all of Aries'/Zeus' methods/properties by using _hero.Aries.whateverFunction(). Hope this steers you in the right direction.

Upvotes: 2

Related Questions