我的var似乎不想从自定义类继承

时间:2015-04-01 11:15:53

标签: actionscript-3 class flash undefined

如果这最终成为一个菜鸟问题,我真的很抱歉。

我有一个var,它被设置为我班级的新对象。但是,每当我测试它时,我都会收到错误1120。我知道错误意味着它是一个未定义的属性。我尝试改变它的范围(到主类中的每个可能的位置。即类,就在导入和构造函数之后)。

该代码应该是Dungeons and Dragons 4e的角色创建者的一部分。

已经尝试了几个小时才找到解决方案,但我只是不确定。如果有任何帮助,将包括我的属性类。

var Humon:Attributes = new Attributes

它被宣布为我的主要课程的一部分:

package
{
//imports
import com.Classes.Attributes;
import flash.text.*;

public class Main extends MovieClip()
{

    private var Humon:Attributes = new Attributes;

    public function Main()
    {
            Atties.text = (Humon.getStr()+", "+Humon.getDex()+", "+Humon.getCon()+", "+Humon.getInt()+", "+Humon.getWis()+",  "+Humon.getCha()+".");
            var res:int = Humon.getStr();
            trace("Humon Str is "+res+".");
        }
    }
}

这是属性类。

//This class defines the frame work for all classes used

package
{

    public class Attributes extends Object
{

//vars go here

//saves variables  (get auto updated through function makeDefaultModsAndSaves())
    static var refSave:int = 0;
    static var forSave:int = 0;
    static var wilSave:int = 0;
//attribute modifiers (get auto updated through function makeDefaultModsAndSaves())
    static var StrMod:int = 0;
    static var DexMod:int = 0;
    static var ConMod:int = 0;
    static var IntMod:int = 0;
    static var WisMod:int = 0;
    static var ChaMod:int = 0;


//2d array to store attributes [x][y] where x is str/dex/con/int/wis/cha and y is value
        static var Attrs:Array = new Array(); 
        Atts[0] = [10]; 
        Atts[1] = [10]; 
        Atts[2] = [10]; 
        Atts[3] = [10]; 
        Atts[4] = [10]; 
        Atts[5] = [10]; 

    function Attributes()
    {
    //constructor
        trace("Attributes loaded");
    }

 //functions to GET Attributes
    function getStr():int
        {
            var Str:int = 0;
            Str = Atts[0][0];
            trace ("Getting Str. It is " + Str);
            return Str;
        }
//different functions, same syntax as getStr above
function getDex():int
    {
        var Dex:int = 0;
        Dex = Atts[1][0];
        trace ("Getting Dex. It is" + Dex);
        return Dex;
    }

function getCon():int
    {
        var Con:int = 0;
        Con = Atts[2][0];
        trace ("Getting Con. It is" + Con);
        return Con;
    }

function getInt():int
    {
        var Int:int = 0;
        Int = Atts[3][0];
        trace ("Getting Int. It is" + Int);
        return Int;
    }

function getWis():int
    {
        var Wis:int = 0;
        Wis = Atts[4][0];
        trace ("Getting Wis. It is" + Wis);
        return Wis;
    }

function getCha():int
    {
        var Cha:int = 0;
        Cha = Atts[5][0];
        trace ("Cha is" + Cha);
        return Cha;
    }

//functions to SET Attributes
function setStr(input:int)
{
    //trace old value
    trace("Old Strength is: "+Atts[0][0]+".");

    //assign new value from whatever source
    Atts[0][0] = input;

    //check new strength
    trace("New Strength is: "+Atts[0][0]+"./n");

    //and update mods/saves
    makeDefaultModsAndSaves()
}

    //different functions, same syntax as getStr above
function setDex(input:int)
{
    trace("Old Dexterity is: "+Atts[0][0]+".");
    Atts[1][0] = input;
    trace("New Dexterity is: "+Atts[0][0]+"./n");
    makeDefaultModsAndSaves()
}

function setCon(input:int)
{
    trace("Old Constitution is: "+Atts[2][0]+".");
    Atts[2][0] = input;
    trace("New Constitution is: "+Atts[2][0]+"./n");
    makeDefaultModsAndSaves()
}

function setInt(input:int)
{
    trace("Old Intelligence is: "+Atts[3][0]+".");
    Atts[3][0] = input;
    trace("New Intelligence is: "+Atts[3][0]+"./n");
    makeDefaultModsAndSaves()
}

function setWis(input:int)
{
    trace("Old Wisdom is: "+Atts[4][0]+".");
    Atts[4][0] = input;
    trace("New Wisdom is: "+Atts[4][0]+"./n");
    makeDefaultModsAndSaves()
}

function setCha(input:int)
{
    trace("Old Charisma is: "+Atts[5][0]+".");
    Atts[5][0] = input;
    trace("New Charisma is: "+Atts[5][0]+"./n");
    makeDefaultModsAndSaves()
}

//function to calculate and apply modifiers based off of ATTRIBUTES ONLY
        function makeDefaultModsAndSaves():int
        {

            for(var i:int = 0; i < Atts.length; i++)
            {
                var modifier: int = 0;
                trace("Current loop: "+i);              
                modifier = (((Atts[i][0])-10)/2);

            switch (i)
            {

           case 0:
           StrMod = modifier;
           trace("Strength is "+Atts[i] +" and has a modifier of "+StrMod+".\n");
           break;

        case 1:
        DexMod = modifier;
        trace("Dexterity is "+Atts[i]+" and has a modifier of "+DexMod+". The reflex save bonus is "+refSave+".\n");
        break;

        case 2:
        ConMod = modifier;
        forSave = modifier;
        trace("Constitution is "+ Atts[i]+" and has a modifier of "+ConMod+". The fortitude save bonus is "+forSave+".\n");
        break;

        case 3:
        IntMod = modifier;
        trace("Intelligence is " +Atts[i]+" and has a modifier of "+IntMod+".\n");
        break;

        case 4:
        WisMod = modifier;
        trace("Wisdom is "+Atts[i]+" and has a modifier of "+WisMod+". The will save bonus is "+wilSave+".\n");
        break;

        case 5:
        ChaMod = modifier;
        trace("Charisma is "+Atts[i]+" and has a modifier of "+ChaMod+".\n");
        break;
        } 


        }
    return modifier;
}

//temporary var to initialise function.
var arse:int = makeDefaultModsAndSaves()


}
}

1 个答案:

答案 0 :(得分:0)

  1. 删除括号:

    public class Main extends MovieClip()
    public class Main extends MovieClip
    
  2. 确保Main.as和Attributes.as放在同一个文件夹中。 删除不必要的import语句:

    import com.Classes.Attributes;
    
  3. 这里有一个错误:

    static var Attrs:Array = new Array();
    Atts[0] = [10];
    Atts[1] = [10];
    Atts[2] = [10];
    ...
    

    重新命名Attts的吸引力。

  4. 在Main.as课程中,您将向Atties发表演讲。什么是Atties?