【问题标题】:Adding a new child movieclip添加新的子影片剪辑
【发布时间】:2015-07-26 18:24:58
【问题描述】:

我正在尝试获取一个立方体动画剪辑来创建其自身的另一个实例,然后将其添加到舞台上前一个旁边的坐标处。但是,我无法继续添加更多孩子/无法弄清楚如何访问孩子的坐标。我试图添加一个新的movieclip:mc for循环的每次迭代,每次垂直和水平倒数50然后,在不同的思考过程中,我尝试在每个循环中添加一个新的孩子,但我不知道如何访问该孩子的属性。任何帮助,将不胜感激。谢谢。

var countV:int=600;
var countH:int=600;
stage.addChild(havenAlpha);
var moveHOrV:Boolean=true;
var mc:MovieClip = new haven_Expand();
for(var i:int=0; i<=5; i++){

            if(moveHOrV == false){
                stage.addChild(mc);
                countH=countH-50;
                mc.x= countH;
                moveHOrV=true;

            }else if(moveHOrV == true){
                stage.addChild(mc);
                countV=countV-50;
                mc.y=countV;
                moveHOrV=false;
            }

            trace(countV,countH,moveHOrV,i);

            stage.addChild(new haven_Expand())
            stage.addChildAt(new haven_Expand(),countH);


        }

【问题讨论】:

    标签: actionscript-3 if-statement for-loop actionscript movieclip


    【解决方案1】:

    在大多数面向对象的语言中,变量只是指向实际对象的指针。因此,更改存储在变量中的内容实际上并不会使之前存储的内容消失。

    为此,您可以只创建一个var 来存储每次迭代创建的每个新对象。像这样:

    stage.addChild(havenAlpha);
    
    //this var will store the clip from the preivous iteration, but we'll start it off with the first item
    var prevClip:MovieClip = new haven_Expand();
    prevClip.x = 600;
    prevClip.y = 600;
    stage.addChild(prevClip);
    
    var curClip:MovieClip; //used in the loop below to hold the current iterations item
    
    for(var i:int=0; i<=5; i++){
        curClip = new haven_Expand();//create new clip
        stage.addChild(curClip); //add it to the stage
        if(i % 2){ // % (modulous) gives you the remainder of the division, so this effectively will be false (0) every other time
            curClip.x = prevClip.x - curClip.width; //place this new clip just to the left of the last iteration's clip
            curClip.y = prevClip.y;
        }else if(moveHOrV == true){
            curClip.y = prevClip.y - curClip.height; //place this new clip just on top of the last iteration's clip
            curClip.x = prevClip.x;
        }
    
        prevClip = curClip;
    }
    

    我不确定 x/y 数学是否是您想要的。这将使它们以对角线方式分布。你真的想要水平行吗?如果需要,我可以更新以向您展示。

    【讨论】:

    • 是的,我将研究算法以使它们分布在屏幕上。谢谢,我试试这个。
    • 我想让它从右下角填满屏幕。有点像洪水填充。所以如果它是一个 3x3 的盒子,它会像这样填充 --- --- --- --- --- --x --x -xx -xx 等等。
    • 我没听懂,你只是想让循环一直持续到屏幕被haven_Expand 剪辑完全覆盖?您可以制作图片并用图片编辑您的问题吗?
    • 所以我正在做的是在屏幕的对角制作一个haven_expand 和一个nonhaven_expand。当他们都试图取一个正方形时,他们会做一个 math.random 并且谁高谁就得到这个正方形。这就像一场比赛。最终我想让它从每一边随机扩展,然后他们会在他们尝试占据中立方格或敌方方格时执行 math.random。也许当前的haven_exapnd 方块应该是背景,然后使用haven_expand 方块作为网格指南扩展另外两个方块。我让 Haven_Expand 剪辑占据了整个屏幕。
    • 我通过更改 If 语句来做到这一点,以便如果 prevClip.x>=100(与您的代码相同)则 Else if(prevClip.x
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-27
    • 2023-03-02
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多