删除影片剪辑AS3 [英] Remove Movie clip as3

查看:162
本文介绍了删除影片剪辑AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定这是我发疯,在过去几个小时,我知道有一个简单的答案。

我有一个滚动窗格有一个影片剪辑名为right_container_mc,因为它的来源。 在这个right_container_mc我有一个名为execiseBox以外的其他影片剪辑得到补充(在正确的位置在舞台上)从数组for循环。 每次练习中有一个称为close_btn一个按钮元件。

首先我不知道,这是为了实现这一目标,以便随时提出一个更好的办法的最佳途径!

在此close_btn单击从阵列和舞台,然后遍历数组再这样删除特定exerciseBox影片剪辑在所有的运动中影片剪辑的更新他们在舞台上的位置,我想要做的就是。

我有麻烦的引用,影片剪辑,因为它是嵌套从数组和舞台将其删除。这里是code我迄今,需要在删除,修改的部分补充。也是我应该删除所有exerciseBox影片剪辑的当前实例的阵列每次循环??运行之前

任何帮助是极大的AP preciated。

 函数addMovieClipsToStage(事件:MouseEvent)方法:无效
   {
    scrollPaneRight.source = right_container_mc;
    exerciseBox =新Exercisebox();
    exerciseBox.close_btn.addEventListener(MouseEvent.CLICK,onRemoveBox);
    boxArray.push(exerciseBox);
    sortBoxes();
    scrollPaneRight.update();
   }

    功能onRemoveBox(事件:MouseEvent)方法:无效
   {

   }

   功能sortBoxes():无效
   {
    对于(VAR我:= 0; I< boxArray.length;我++)
    {
     right_container_mc.addChild(exerciseBox);
     exerciseBox.x = 0;
     exerciseBox.y =((115 + 3)*ⅰ);

    }

   }
 

解决方案

在你的onRemoveBox功能

event.currentTarget应该返回该功能是由触发的对象。

眼看作为对象是right_container_mc的孩子,也许你可以试试:

  right_container_mc.removeChild(event.currentTarget);
 

根据于code您已经张贴我不知道,你甚至不需要一个数组。它看起来像你用它来追踪儿童的数量。显示列表已经这样做了你。

所以,我认为你的排序可能只是引用 right_container_mc.numChildren 而不是数组的长度。

希望一些这方面的帮助!

Ok this has been driving me nuts for the past couple of hours and i know there is an easy answer.

I have a scrollPane which has a movie clip called right_container_mc as it's source. Inside this right_container_mc I have other other movie clips called execiseBox that get added (in the correct positions on the stage) from an array with a for loop. Each exercise box has a button symbol called close_btn.

Firstly I'm not sure that this is the best way to achieve this so feel free to suggest a better way!

What I want to do is when this close_btn is clicked remove the specific exerciseBox movieclip from the array and from the stage then loop through the array again so all of the exercise box movieclips update their position on the stage.

I am having trouble getting a reference to the movie clip because it is nested to remove it from the array and stage. Here is the code I have so far, need to add in the removing and updating parts. Also is should I be removing all of the current instances of the exerciseBox movie clips before the array loop runs each time??

Any help is greatly appreciated.

 function addMovieClipsToStage(event:MouseEvent):void
   {
    scrollPaneRight.source = right_container_mc;
    exerciseBox = new Exercisebox();
    exerciseBox.close_btn.addEventListener(MouseEvent.CLICK, onRemoveBox);
    boxArray.push(exerciseBox);
    sortBoxes();
    scrollPaneRight.update();
   }

    function onRemoveBox(event:MouseEvent):void
   {

   }

   function sortBoxes():void
   {
    for (var i:int =0; i<boxArray.length; i++)
    {
     right_container_mc.addChild(exerciseBox);
     exerciseBox.x = 0;
     exerciseBox.y = ((115 + 3)*i);

    }

   }

解决方案

in your onRemoveBox function

event.currentTarget should return the object that function was triggered by.

Seeing as that object is a child of right_container_mc maybe you could try:

right_container_mc.removeChild(event.currentTarget);

Based upon the code you have posted I'm not sure you even need an array. It looks like you're using it to keep track of the number of children. Display list already does this for you.

So I think your sort could just reference right_container_mc.numChildren instead of an array length.

Hope some of this helps!

这篇关于删除影片剪辑AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆