as3.0中的removeChild的用法
改成这个样子:
var anxia:Boolean=false
var arr:Array = new Array();
stage.addEventListener(MouseEvent.MOUSE_DOWN,hua)
stage.addEventListener(MouseEvent.MOUSE_UP,ting)
stage.addEventListener(Event.ENTER_FRAME,huahua)
function hua(event:MouseEvent){
anxia=true
}
function ting(event:MouseEvent){
anxia=false
}
function huahua(event:Event){
if (anxia) {
var dian:Sprite=new Sprite()
dian.graphics.lineStyle(0,0x000000)
dian.graphics.beginFill(0x000000)
dian.graphics.drawCircle(0,0,2)
dian.x=mouseX
dian.y=mouseY
this.addChild(dian)
arr.push(dian);
}else{
if(arr.length > 0){
for(var i:int=0;i<arr.length;i++){
if(this.contains(arr[i])){
this.removeChild(arr[i]);
}
}
arr = [];
}
}
}
【Flash】AS3.0 RemoveChild()问题
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class Information extends MovieClip
{
var hp:int;
var money:int;
var weapon:int;
var shopExist:Boolean;
public function Information()
{
shopExist = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
}
function onKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.CONTROL)
{
if(shopExist)
{
这里压根就没有RemoveChild.shopMenu这样的属性,我不知你怎么写出来的。其实显示容器到是有个方法 就是removeChild
xxx.RemoveChild.shopMenu;//////这句怎么改都错。。。前面填啥??
}
if (!shopExist)
{
var shopMenu:ShopMenu;
shopMenu = new ShopMenu;
stage.addChild(shopMenu);
这个没加路径,是因为当前路径就是当前的域,你在前面创建了对象,在这里能不能访问吗?
shopMenu.x=400; /////这句没有加shopMenu的路径,为啥可以访问?
shopMenu.y=320; /////同上
shopExist=true;
}
}
}
}
}