从舞台上移除精灵

发布于 2024-09-19 17:41:22 字数 1128 浏览 5 评论 0原文

大家好,我的 Flash 页面出现问题。所以我创建了 5 个页面,每个页面都包含几个影片剪辑(文本、图形、表单等)。然而,有一个特定页面包含通过自动生成的内容。精灵。如果我碰巧登陆这个页面,精灵就会出现,但是当我转换到另一个页面时,除了非精灵的东西(消失)之外,它们仍然在那里。我在这个上抓狂了,我设法删除了一些精灵,但有些仍然出现。下面显示了未删除的布局;

var container:Sprite = new Sprite();

//loop places several "item" in this container sprite and a scroll bar
var item:myItem = new myItem();
var sb:customScrollBar = new customScrollBar();

container.addChild(item);
container.addChild(sb);

所以我们现在在生成容器和项目的页面上,然后我单击一个按钮移动到主页,容器仍然留在那里。

这是我尝试过的:

removeChild(container); //nothing, this was called from another keyframe where the container was not generated from
stage.removeChild(container); //nothing

这是错误。 ArgumentError:错误#2025:提供的 DisplayObject 必须是调用者的子级。

笔记* 我还有几个按钮,它们也不是在容器内生成的,如下所示,它们在我运行removeChild(button1)时工作,所以我不知道为什么容器按钮不工作。

FLA (cs4) http://www.4shared.com/file/2swJjnNm/mevame.html

预览 http://bodog-bonuses.com/mevame/

Hey guys, got a problem with my pages in flash. So i created 5 pages, each of which contains several movie clips (text, graphics, forms, etc). There is one specific page however that contains autogenerated content via. sprites. If i happen to land on this page, the sprites will appear, but when i transition to another page, they are still there except for the non-sprite stuff (disappear). Im ripping my hair out on this one, i managed to get a few of the sprites to remove but some are still appearing. Below shows the layout of the one thats not being removed;

var container:Sprite = new Sprite();

//loop places several "item" in this container sprite and a scroll bar
var item:myItem = new myItem();
var sb:customScrollBar = new customScrollBar();

container.addChild(item);
container.addChild(sb);

So we are now on this page where container and items are generated, i then click a button to move to say the home page and the container still stays there.

Here is what i tried:

removeChild(container); //nothing, this was called from another keyframe where the container was not generated from
stage.removeChild(container); //nothing

Here are the errors.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

Note*
I also have several buttons that were also generated NOT inside the container like below and they worked when i ran removeChild(button1) so i dont know why the container one is not working.

FLA (cs4)
http://www.4shared.com/file/2swJjnNm/mevame.html

Preview
http://bodog-bonuses.com/mevame/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

刘备忘录 2024-09-26 17:41:22

则不会收到参数错误 2025,

//initialization
var container:Sprite = new Sprite();

...... 
......
addChild(container);

//------- later
if(contains(container))
  removeChild(container);

如果您遵循“无需创建名称”, 这是保证 sprite 或 DisplayObject 被添加到 DisplayList 的原因。那么你不会得到 y ArgumentError 2025 。

You will not get an Argument error 2025 IF you follow

//initialization
var container:Sprite = new Sprite();

...... 
......
addChild(container);

//------- later
if(contains(container))
  removeChild(container);

No need to create a name this is guarentee that the sprite or DisplayObject is added to the DisplayList. You will not get an y ArgumentError 2025 then.

哑剧 2024-09-26 17:41:22

之前我也遇到过类似的情况,我通过执行以下操作解决了。这取决于我如何创建容器实例并因此被父级识别。

var container:Sprite = new Sprite();
container.name = "container";

//------- later
var child:DisplayObject = getChildByName("container");
removeChild(child);

如果您需要删除所有孩子,您也可以这样做

while( this.numChildrem > 0 )
     this.removeChildAt(0);

Something similar happened to me before which I solved by doing the following. It depends on how your instances of container I created and therefore recognized by the parent.

var container:Sprite = new Sprite();
container.name = "container";

//------- later
var child:DisplayObject = getChildByName("container");
removeChild(child);

If you need to remove all children you could also do this

while( this.numChildrem > 0 )
     this.removeChildAt(0);
放血 2024-09-26 17:41:22

这可能是由于以下事实造成的:对于时间轴动画,任何给定的关键帧都可能包含一个对象,但是对于每个关键帧操作列表,您会失去前一个关键帧内容的范围。因此,如果您在跨越新的时间线关键帧之前调用“remove child”,则可能能够在容器上成功调用“removeChild”。

否则,您可以利用帕特里克的建议,它肯定会找到舞台上的对象并将其删除,尽管这是从显示列表中检索对象的效率较低的方法之一。

This is likely caused by that fact that with a timeline animation, any given keyframe may contain an object however with each keyframed list of actions, you lose scope on the previous keyframe's contents. So if you call remove child before you cross a new timeline keyframe, you will likely be able to successfully call removeChild on the container.

Otherwise, you can utilize Patrick's suggestion, which will definitely find the object on the stage and remove it, though it is one of the more inefficient means of retrieving an object from the display list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文