Search code examples
actionscript-3flashair

AS3 Flash CS6 object Base class and Class


I seem to be having a tiny bit of a problem, I'm createing a new movieclip as a variable with AS3, now the AS file is Monster.AS, with my object if i give it the base class as Monster and the class as Monster1, the monster code is ran, because I have a trace message, but it is not displayed on the screen, if i change the base class to flash.display.MovieClip and change the class to Monster, it runs the code and displays the enemy... I'm very confused on why it displays and doesn't display because of how the base class works, here is the code that creates the monster

This is the code snippet of Level.as

    public function Level( playerHero:HeroDisplay )
    {
        trace("Level code ran");
        monsterArray = new Array();
        heroGra = playerHero;
        addChild( heroGra );
        var newMonster = new Monster();
        monsterArray.push( newMonster );
        addChild( newMonster );
        setupLevel(1);
        //Buttons
        this.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
        this.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
        this.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
    }

this works for both, but as i stated above, if Base Class = Monster Class = Monster1 wont be displayed if Base Class = flash.display.MovieClip Class = Monster will be displayed.

Anyone know why?

Canvas

More information, Here is the image of the class + base class

enter image description here

Also here is the monster AS file

package
{
import flash.display.MovieClip;

public class Monster extends MovieClip
{
    public var id:Number;
    public var hp:Number;
    public var damage:Number;
    public var speed:Number;
    public var xPos:Number;
    public var yPos:Number;
    public var avaiableSkill:Number;

    public function Monster()
    {
        id = 1;
        monsterSetup();
    }

    public function monsterSetup():void
    {
        switch(id)
        {
            case 1: hp = 10; damage = 1; speed = 2; avaiableSkill = 0; this.x = 100; this.y = 150; trace("Monster Setup");
            break;
            default:
            break;
        }
    }
}
}

Solution

  • Your Monster class has no visual aspect.

    Monster1, is what I am assuming has your monster artwork, correct ?

    To use the Monster1 class you can use this code :

    var newMonster:Monster1 = new Monster1;
    addChild(newMonster);
    

    I'm not really clear on what your approach is, but based on your setup you are never creating an instance of the visual element - which is the Monster1 class.