Okt
14

Problem with the Event-target and removeChild

By Hannes  //  Allgemein  //  No Comments

Today i played a bit with a touchscreen and flash at the finish agency. I tried to program a simple game you have to remove clouds as fast as you can and a new cloud appears each 0.5 seconds. If you click on of the clouds it will disapear. The Code is really simple but i get a problem with removing the childs after clicking them.

function removeCloud(evt:MouseEvent):void{
	evt.target.removeEventListener(MouseEvent.CLICK, removeCloud)
	this.removeChild(evt.target);
 
}

The compiler always returend an error: 1118:Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:DisplayObject.

After a bit trail and error i mentioned the right syntax is:

function removeCloud(evt:MouseEvent):void{
	evt.target.removeEventListener(MouseEvent.CLICK, removeCloud)
	this.removeChild(MovieClip(evt.target));
 
}

Maybe this helps somebody somday :)

Gib deinen Senf ab

Letzte Tweets

Archiv