复选框将元素添加到数组

时间:2013-06-15 02:13:48

标签: actionscript-3

我似乎遇到了将元素插入数组的问题。 我想要做的是,如果CheckBox是勾选,它会在数组中插入一个元素,如果复选框未选中,则从数组中删除元素

package src
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;

public class Main extends MovieClip
{   
    var positionY:Number = 80;
    var positionX:Number = 0;
    var motion:MovieClip;
    var fCombo:Array = new Array();
    var n:Number;
    var combo:Array = new Array();

public function Main()
{
    Basic.selected = true;
    Basic.addEventListener(Event.CHANGE, change);
    generate.addEventListener(MouseEvent.MOUSE_UP, loop); 
    generate.addEventListener(MouseEvent.MOUSE_DOWN, remove); 
    n = Number(inputText.text);
    var combo:Array = [];
}
function loop(me:MouseEvent):void
{


    var combo:Array = [Punch, Kick, Knee, Elbow];
    n = Number(inputText.text);
    for(var i:Number = 0;i < n;i++ )
        {
        motion = new combo[randomNumber(combo.length)]();  
        fCombo.push(motion);
        motion.y = positionY;
        motion.x = positionX;
        positionX += 100;
        addChild(motion);
        if (i == 4 || i == 9 || i == 14 || i == 19)
                {
                    positionY += 40;
                    positionX = 0;
                }
        }
}
function remove(me:MouseEvent):void
{
    var k:Number = n
 while(fCombo.length)
{
    removeChild(fCombo.pop());
}
    positionY = 80;
    positionX = 0;
}

function randomNumber(max:Number):Number
    {
    return(Math.floor(Math.random() * max ));
    }


function change(e:Event):void
{
    if (Basic == true)
    {
        combo.push(UpperCut); //this movieclip won't insert inside the array
    }
}
}

}

1 个答案:

答案 0 :(得分:0)

我猜Basic是一个复选框,所以

if (Basic == true)
{
    combo.push(UpperCut); //this movieclip won't insert inside the array
}

应该是

if (Basic.selected == true)
{
    combo.push(UpperCut); //this movieclip won't insert inside the array
}