0

我似乎在将元素插入数组时遇到问题。我想要做的是,如果 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
    }
}
}

}
4

1 回答 1

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
}
于 2013-06-15T03:01:52.700 回答