0

我必须将对象列表添加到数组中,以便稍后访问它们,但由于某种原因,我之前添加的对象播放,我将它们添加到显示列表中。这是代码:

添加列表的框架:

sunny.addEventListener(MouseEvent.CLICK, sunny_choice);

function sunny_choice(E:MouseEvent)
{
    var sunny_walkcycle: Sunny_Walkcycle = new Sunny_Walkcycle ();
    var sunny_busstop : Sunny_BusStop = new Sunny_BusStop ();
    var sunny_opening: Teacher_Opening_Sunny = new Teacher_Opening_Sunny ();


    clothingArray.push( sunny_walkcycle);
    clothingArray.push( sunny_busstop);
    clothingArray.push( sunny_opening);

    trace("Sunny");
    cleaner();
//cleaner just removes the event listener and asks it to go to the next frame
}

下一帧:

clothingArray [0].scaleX = -1;

addChild (clothingArray [0]);
clothingArray[0].x = 633;
clothingArray[0].y = 174;
clothingArray [0].stop ();
clothingArray [0].addEventListener (MouseEvent.CLICK, transforming);


function transforming (e:MouseEvent) {
    if (clothingArray [0].currentFrame == clothingArray [0].totalFrames) {
        clearall2 ();

    }
    else{
    clothingArray  [0].nextFrame();
    moving_background.nextFrame ();
    }

}
function clearall2 () {
    clothingArray [0].removeEventListener (MouseEvent.CLICK, transforming);
    removeChild (clothingArray [0]);

    gotoAndStop (3);
}

有问题的一:

addChild (clothingArray [1]);
clothingArray[1].addEventListener (Event.ENTER_FRAME , busstop);
trace ("The Current Frame is " + clothingArray [1].currentFrame);
function busstop (d:Event) {
        if (clothingArray [1].currentFrame == clothingArray  [1].totalFrames) {
        clearall3 ();

    }
}

function clearall3 () {
    removeChild (clothingArray [1]);
    clothingArray[1].removeEventListener (Event.ENTER_FRAME , busstop);

    }

所以它的确切作用是第 3 帧中的电影剪辑在它添加到显示列表之前开始播放,我不确定是什么原因造成的......我不能在这一帧单独添加变量,因为第 1 帧中有其他选项这导致我制作一个数组。

4

2 回答 2

1

假设 Sunny_Walkcycle、Sunny_BusStop、Teacher_Opening_Sunny 是 MovieClip,为什么不在内存分配后直接使用 stop() 呢?

  var sunny_walkcycle:Sunny_Walkcycle = new Sunny_Walkcycle ();
  var sunny_busstop:Sunny_BusStop = new Sunny_BusStop ();
  var sunny_opening:Teacher_Opening_Sunny = new Teacher_Opening_Sunny ();

  sunny_walkcycle.stop();
  sunny_busstop.stop();
  sunny_opening.stop();

确保您的 MovieClip 内帧中没有代码会与您的控制代码混淆。就像一个 play()... 隐藏在某个地方。

您也可以在推入数组后尝试(对于 Sunny_busstop):

clothingArray[1].stop();

或者

clothingArray[1].gotoAndStop(1);
于 2013-04-15T03:35:17.557 回答
1

是的,MovieClip 将在创建后开始播放。无需添加到显示列表即可激活。这是非常重要的细节,需要理解。

显示列表仅确定显示对象是否连接到阶段层次结构。

解决方案... 创建后调用该stop()方法,然后在play()将它们添加到显示列表时调用该方法。

如果您在从显示列表中删除时不调用该stop()方法,它将继续消耗 cpu 周期。如果您有许多带有补间等的 MovieClip,这可能非常重要。

于 2013-04-15T03:35:33.413 回答