首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >影片剪辑在添加到DisplayList之前是否正常工作?

影片剪辑在添加到DisplayList之前是否正常工作?
EN

Stack Overflow用户
提问于 2013-04-15 10:52:32
回答 2查看 47关注 0票数 0

我必须将对象列表添加到数组中,以便以后可以访问它们,但由于某些原因,我之前添加的对象,我将它们添加到显示列表中。代码如下:

添加列表的框架:

代码语言:javascript
复制
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
}

下一帧:

代码语言:javascript
复制
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);
}

有问题的那个:

代码语言:javascript
复制
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帧中有其他选项导致我创建一个数组。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-15 11:35:18

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

代码语言:javascript
复制
  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),就在数组推入之后:

代码语言:javascript
复制
clothingArray[1].stop();

代码语言:javascript
复制
clothingArray[1].gotoAndStop(1);
票数 1
EN

Stack Overflow用户

发布于 2013-04-15 11:35:33

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

显示列表仅确定显示对象是否连接到舞台层次。

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

如果在从显示列表中删除时不调用stop()方法,它将继续占用cpu周期。如果你有大量的补间等MovieClips,这可能是相当重要的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16006986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档