0

这很难解释。

我的目标是每次单击时根据鼠标的 X/Y 轴放置绵羊(符号)...。我希望它生成绵羊的副本但我也希望每个副本都是不同的图像..(每次单击鼠标时,它都会更改绵羊符号内的图像(放置在不同的框架上)。

如果有人可以提供帮助,我将非常感激!

这是代码:

stage.addEventListener (MouseEvent.CLICK, makeABox);


var i:Number = 1;


function makeABox(e:Event):void {

    var newSheep:myMC = new myMC();

    addChild(newSheep);

    newSheep.x = stage.mouseX;

    newSheep.y = stage.mouseY;

    i++;

}



var numPressed:Number = 0;
stage.addEventListener(MouseEvent.CLICK, countUp);

function countUp(evt:MouseEvent):void {
numPressed++;


if (numPressed == 1) {
    sheep.gotoAndPlay(1);
}

else if (numPressed == 2) {
    sheep.gotoAndPlay(2);
}

else if (numPressed == 3) {
    sheep.gotoAndPlay(3);
}

else if (numPressed == 4) {
    sheep.gotoAndPlay(4);
}

else if (numPressed == 5) {
    sheep.gotoAndPlay(5);
}

else if (numPressed == 6) {
    sheep.gotoAndPlay(6);
}

else if (numPressed == 7) {
    sheep.gotoAndPlay(7);
}

if(numPressed >= 7) numPressed = 0;

}
4

1 回答 1

1

将您在问题中发布的所有代码替换为:

stage.addEventListener (MouseEvent.CLICK, addSheep);

var sheepCounter:int = 1;

function addSheep(event:MouseEvent):void {
    //create new sheep
    var newSheep:myMC = new myMC();
    //position it at mouse click
    newSheep.x = stage.mouseX;
    newSheep.y = stage.mouseY;
    //set frame of sheep to display
    newSheep.gotoAndStop(sheepCounter);
    //add sheep to display list
    addChild(newSheep);
    //update counter
    sheepCounter++;
    if (sheepCounter==8)
    {
        sheepCounter = 1;
    }
}
于 2013-01-19T18:07:09.910 回答