A3电影剪辑阵列

时间:2014-06-27 08:07:39

标签: arrays actionscript-3 movieclip

[AS3.0]我目前正在攻读毕业证书,我遇到了使用相同实例名称管理movieClips的问题。我在第1帧中使用此类和数组创建了一个对象数组:

package 
{
    import flash.display.MovieClip;

    public class createFractionBuilding
    {
        public function createFractionBuilding(_fractionBuildingMovieClip:MovieClip, _fractionBuildingLevel:Number,_fractionBuildingCost:Number, _fractionBuildingFrame:Number)
        {
            fractionBuildingLevel = _fractionBuildingLevel;
            fractionBuildingCost = _fractionBuildingCost;
            fractionBuildingMovieClip = _fractionBuildingMovieClip
            fractionBuildingFrame = -fractionBuildingFrame
        }

        public var fractionBuildingLevel:Number,fractionBuildingCost:Number,fractionBuildingFrame:Number;
        public var fractionBuildingMovieClip:MovieClip
    }
}

在主时间轴上,我通过创建一个对象数组来引用这个类:

var allHumanBuildingsList:Array = new Array();

var humanCapitolBuildingProperties:createFractionBuilding = new createFractionBuilding(humanCapitol_mc,1,1000,1);
var humanCastleBuildingProperties:createFractionBuilding = new createFractionBuilding(humanCastle_mc,2,1000,1);

allHumanBuildingsList.push(humanCapitolBuildingProperties);
allHumanBuildingsList.push(humanCastleBuildingProperties);

为了实现这一点,我必须使用名为" humanCapitol_mc"的电影剪辑。或" humanCastle_mc"在这个框架(1)。

但是在第(2)行中我想用这样的函数来引用这个movieClip:

function humanBuildingLevelCheck()
{
    for (var a:Number = 0; a < allHumanBuildingsList.length; a++)
    {
        trace (String(allHumanBuildingsList[a].fractionBuildingMovieClip))
        if (allHumanBuildingsList[a].fractionBuildingLevel == 2){
            allHumanBuildingsList[a].fractionBuildingMovieClip.gotoAndStop(3)
        } else if (allHumanBuildingsList[a].fractionBuildingLevel == 1){
            allHumanBuildingsList[a].fractionBuildingMovieClip.gotoAndStop(2)
        }
    }
}
humanBuildingLevelCheck()

(第一帧的每个MovieClip都是空白,第二帧是一张图片,第三帧是不同的一张)

当数组创建代码在第二帧时,一切正常,但它不会按照我想要的方式工作:首先我创建变量和对象,然后动态地更改它的值。你知道吗,这怎么可能?

1 个答案:

答案 0 :(得分:0)

让它全球化。如果在关键帧1中声明了一个变量,则无法在关键帧2中看到它,但如果在一个只有一个关键帧的图层中声明它,那么它将在该时间轴内的任何位置都可见。