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

问题描述

什么是相当于 removeMovieClip()在AS3?

显然,许多有同样的疑问:
计算器:

  1. 如何完全在AS3中删除影片剪辑
  2. 删除影片剪辑AS3
  3. How除去childmovieclip并添加新的父影片剪辑

其他:

  1. removeMovieClip(本)在AS3?
  2. 销毁/删除影片剪辑???
  3. 删除影片剪辑

但是,没有他们的解决方案似乎工作,对我来说:

进出口工作在闪存CS4 AS3

我有一个非常简单的电影有一个按钮叫的点击的。在pressing按钮,一个新实例的硬币的创建:

  this.click.addEventListener(MouseEvent.CLICK,justclick);
功能justclick(E:的MouseEvent){
    VAR钱=新币
    this.addChild(钱)
    money.x = e.stageX
    money.y = e.stageY
}
 

这可能不是最好的code,但它工作正常。现在,硬币影片剪辑是为了显示一个小动画,并删除自身。在良好的旧AS2我会说:

  this.removeMovieClip()
 

在动画的最后一帧。但是,这并不在AS3中存在。
我都试过了,没有成功:

  this.parent.removeChild(本)//不能访问nullobject参考属性或方法...

this.removeMovieClip()//'removeMovieClip不是一个函数

removeMovieClip(本)//'调用可能未定义的方法removeMovieClip

unloadMovie(本)//'调用可能未定义的方法removeMovieClip
 

解决方案?

谢谢

解决方案

  this.parent.removeChild(本);
 

这应该是工作;这是我使用。有一个问题我有,当我切换到AS3的是,有时它会不会被添加作为一个孩子的权利,所以你可能要检查。您也可以通过把这个顶部导入flash.display使用,如果您还不:

 进口flash.display使用。*
 

您也应该删除它之前删除就可以了事件侦听器。

What is the equivalent to removeMovieClip() in AS3?

Apparently many have the same question:
StackOverflow:

  1. How to completely remove a movieclip in as3
  2. Remove movie clip as3
  3. How to remove childmovieclip and add to new parent movieclip

Others:

  1. removeMovieClip(this) in AS3?
  2. Destroy/Delete a Movieclip???
  3. Remove movie clip

But none of their solutions seem to work, for me:

Im working on flash CS4 with AS3:

I have a very simple movie with a single button called click. On pressing the button, a new instance of coin is created:

this.click.addEventListener(MouseEvent.CLICK,justclick);
function justclick(e:MouseEvent){
    var money=new coin
    this.addChild(money)
    money.x=e.stageX
    money.y=e.stageY
}

It might not be the best code, but it works fine. Now, the coin MovieClip is supposed to show a small animation and remove itself. In good old AS2 I would have added:

this.removeMovieClip()

in the last frame of the animation. But this doesn't exist in AS3.
I have tried, without success:

this.parent.removeChild(this) // 'Cannot access a property or method of nullobject reference'...     

this.removeMovieClip() // 'removeMovieClip is not a function'      

removeMovieClip(this) //'call to possibly undefined method removeMovieClip'       

unloadMovie(this)//'call to possibly undefined method removeMovieClip'       

Solutions?

Thanks,

解决方案
this.parent.removeChild(this);

This one should be working; it's what I use. One problem I had when I switched to AS3 is that sometimes it wouldn't be added as a child right, so you might want to check that. You also have to import flash.display via putting this at the top if you're not already:

import flash.display.*

You should also remove the event listener on it before removing it.

这篇关于如何使一个影片剪辑删除自己在AS3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 19:59