Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 将同一对象的多个实例添加到阶段_Actionscript 3_Object - Fatal编程技术网

Actionscript 3 将同一对象的多个实例添加到阶段

Actionscript 3 将同一对象的多个实例添加到阶段,actionscript-3,object,Actionscript 3,Object,我正在做一个“吐”牌游戏,我试图在舞台上同时有3张牌,以便能够拖到牌堆上。因此,我的问题是,我如何在舞台上拥有同一对象的多个实例,但能够为每张卡分配不同的帧,等等。下面是理解其上下文的代码 “cardArray”有53帧,其中52帧有一个卡片面,第53帧是一张“卡片组”图片 //变量、常量 var cardDeck:Array=new Array(); var定时器:定时器=新定时器(2000); var j:int=0; var卡:MovieClip=新卡阵列(); var-cardInDec

我正在做一个“吐”牌游戏,我试图在舞台上同时有3张牌,以便能够拖到牌堆上。因此,我的问题是,我如何在舞台上拥有同一对象的多个实例,但能够为每张卡分配不同的帧,等等。下面是理解其上下文的代码

“cardArray”有53帧,其中52帧有一个卡片面,第53帧是一张“卡片组”图片

//变量、常量
var cardDeck:Array=new Array();
var定时器:定时器=新定时器(2000);
var j:int=0;
var卡:MovieClip=新卡阵列();
var-cardInDeck:布尔型;
常数deckSize:int=52;
//活动:
card.addEventListener(MouseEvent.MOUSE_DOWN,fDown);
card.addEventListener(MouseEvent.MOUSE_UP,fUp);
星域();
//这就是创建非缓冲“组块”的地方——将值加载到数组中。
函数createDeck():void
{
变量i:int;
对于(i=0;i.5)?1:-1;
}
//从卡的(大概)当前帧中获取值
功能转换卡(卡号:int):int
{
位置:int;
if(卡号甲板尺寸/4和卡号甲板尺寸/2和卡号39)
{
deckPos=卡号-39;
}
返回deckPos;
}
btn.addEventListener(MouseEvent.MOUSE\u UP,showArray);
函数showArray(事件:MouseEvent):void
{

如果(j要拥有多张牌,您需要实例化多张牌。我对纸牌游戏spit一无所知,也不了解您的许多功能的用途,但您需要按照以下思路做一些事情:

创建生成(实例化)新卡的函数:

function createCard(faceFrame):MovieClip {
    var tmpCard:MovieClip = new CardArray(); //this creates a new instance of a card 
    tmpCard.addEventListener(MouseEvent.MOUSE_DOWN, cardMouseDown); //make the card call the mouse down function when that event is triggered
    tmpCard.gotoAndStop(faceFrame); //assign the card it's face (frame)
    addChild(tmpCard); //add the card to the screen

    return tmpCard;
}  
然后,在鼠标按下处理程序中(我将其重命名为更清楚的“是”),您可以对鼠标按下的卡执行以下操作:

function cardMouseDown(evt:MouseEvent) {
    //the events currentTarget property is reference to the item that you attached the listener to, so in this case the card who triggered the mouse down
    card = evt.currentTarget as MovieClip; //assign the current clicked card to the global card variable (so we can access it in the mouse up function)
    card.startDrag();

    //add the mouse up listener on the stage, since there are cases where you can drag so fast that the mouse isn't over the item it's dragging (and then if you were to release the mouse at that moment it wouldn't dispatch the event)
    stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
}
然后,您的鼠标向上移动功能将如下所示:

function stageMouseUp(evt:MouseEvent) {
    //remove the mouse up listener from the stage
    stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUp);

    card.stopDrag();
    if(card.hitTestObject(deck))
    {
    ......//rest if the code
function showArray(event:MouseEvent):void
{
    var newCard:MovieClip = createCard(cardDeck[j]);
    j++

    newCard.y = newCard.x = 200;

    trace(cardDeck[j]+","+deckCompare[j]);            
}
似乎您希望在您拥有的
showArray
函数中生成一张新卡?因此类似以下内容:

function stageMouseUp(evt:MouseEvent) {
    //remove the mouse up listener from the stage
    stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUp);

    card.stopDrag();
    if(card.hitTestObject(deck))
    {
    ......//rest if the code
function showArray(event:MouseEvent):void
{
    var newCard:MovieClip = createCard(cardDeck[j]);
    j++

    newCard.y = newCard.x = 200;

    trace(cardDeck[j]+","+deckCompare[j]);            
}

作为一个旁白,你应该考虑调用你的卡对象更明智一些,比如“代码>卡<代码>,而不是<代码> CardArray <代码>,因为它不是一个数组…

有多个卡,你需要实例化一个以上的卡。我不知道任何关于卡游戏的唾沫,不明白你的许多功能的目的,但您需要按照以下思路做一些事情:

创建生成(实例化)新卡的函数:

function createCard(faceFrame):MovieClip {
    var tmpCard:MovieClip = new CardArray(); //this creates a new instance of a card 
    tmpCard.addEventListener(MouseEvent.MOUSE_DOWN, cardMouseDown); //make the card call the mouse down function when that event is triggered
    tmpCard.gotoAndStop(faceFrame); //assign the card it's face (frame)
    addChild(tmpCard); //add the card to the screen

    return tmpCard;
}  
然后,在鼠标按下处理程序中(我将其重命名为更清楚的“是”),您可以对鼠标按下的卡执行以下操作:

function cardMouseDown(evt:MouseEvent) {
    //the events currentTarget property is reference to the item that you attached the listener to, so in this case the card who triggered the mouse down
    card = evt.currentTarget as MovieClip; //assign the current clicked card to the global card variable (so we can access it in the mouse up function)
    card.startDrag();

    //add the mouse up listener on the stage, since there are cases where you can drag so fast that the mouse isn't over the item it's dragging (and then if you were to release the mouse at that moment it wouldn't dispatch the event)
    stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
}
然后,您的鼠标向上移动功能将如下所示:

function stageMouseUp(evt:MouseEvent) {
    //remove the mouse up listener from the stage
    stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUp);

    card.stopDrag();
    if(card.hitTestObject(deck))
    {
    ......//rest if the code
function showArray(event:MouseEvent):void
{
    var newCard:MovieClip = createCard(cardDeck[j]);
    j++

    newCard.y = newCard.x = 200;

    trace(cardDeck[j]+","+deckCompare[j]);            
}
似乎您希望在您拥有的
showArray
函数中生成一张新卡?因此类似以下内容:

function stageMouseUp(evt:MouseEvent) {
    //remove the mouse up listener from the stage
    stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUp);

    card.stopDrag();
    if(card.hitTestObject(deck))
    {
    ......//rest if the code
function showArray(event:MouseEvent):void
{
    var newCard:MovieClip = createCard(cardDeck[j]);
    j++

    newCard.y = newCard.x = 200;

    trace(cardDeck[j]+","+deckCompare[j]);            
}

作为一个旁白,你应该考虑调用你的卡对象,如<代码>卡>代码>而不是<代码> CardArray <代码>,因为它不是一个数组…< /p>你必须每次生成一个新的<代码> CardArray <代码>对象,随机选择这张新卡的帧。code>CardArray

对象并随机选择这张新卡的边框。@ajar-你找到它了吗?每次新的
CardArray
对象并随机选择这张新卡的边框时,你都必须生成它。@ajar-你找到了吗?