I am creating a horizontal platform game in Flash, and I'm trying to create a function that removes the MovieClip that contains the obstacles which you can crash into, before adding the entire map again, making a kind of a restart.
blockArr contains half of the obstacles.
flameArr contains the other half.
These arrays are filled in the Map1-function.
The function:
function removeBlocks(TimerEvent):void{
for (var t:int = 0; t < blockArr.length; t++){
if(blockArr[t] == null){
blockArr = [];
}
if(blockArr[t] != null){
if(contains(blockArr[t])){
blockArr[t].parent.removeChild(blockArr[t]);
blockArr[t] = null;
}
}
if(flameArr[t] == null){
flameArr[t] = [];
}
if(flameArr[t] != null){
if(contains(flameArr[t])){
flameArr[t].parent.removeChild(flameArr[t]);
flameArr[t] = null;
}
}
trace(blockArr);
if(blockArr == []){
Map1();
removeMapTimer.stop();
blockMoveTimer.start();
}
}
}
However, this code returns this error:
TypeError: Error #1034: Type Coercion failed: cannot convert []@2754c641 to flash.display.DisplayObject.
at ImpGameWork14_fla::MainTimeline/removeBlocks() [ImpGameWork14_fla.MainTimeline::frame2:98]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
The intention for this code is to remove and delete the content of these arrays, as that is the obstacles/map. Afterwards, it will check whether the main obstacle array is empty if(blockArr == [])
and if it is, deploy the Map1-function, which adds obstacles to arrays and to stage (addChild(obstacle)). Any help on how to achieve that goal?
blockArr = [];
. Anyways - find the line with the error and check what's wrong. Also, ifcontains(blockArr[t])
, this means you can just useremoveChild(blockArr[t])
instead of this freaky.parent.removeChild
... – Andrey Popovif (blockArr.length == 0)
. – Andrey Popov