Hi here is my code:
var arrows:Array = new Array();
var gameTimer:Timer = new Timer(1000); // 1 second
var maxTime:int;
var Time:int = 2;
var arrow_speed:int = 5;
maxTime = Time;
gameTimer.start();
import flash.display.MovieClip;
function Arrows(event:Event) {
MoveArrows();
if(maxTime == 0){
if(arrows.length<3){
var arrow_type:int = Math.random()*3;
trace("Jepu: "+arrow_type);
getArrows(arrow_type);
maxTime = Time;
}
}
}
function getArrows(type){
switch(type){
case 0:
var arrow1:Arrow = new Arrow();
arrow1.gotoAndStop(1);
arrow1.x = 20;
arrow1.y = 0;
stage.addChild(arrow1);
trace("Object: "+arrow1.name);
arrows.push(arrow1);
break;
case 1:
var arrow2:Arrow = new Arrow();
arrow2.gotoAndStop(2);
arrow2.x = 120;
arrow2.y = 0;
stage.addChild(arrow2);
trace("Object: "+arrow2.name);
arrows.push(arrow2);
break;
case 2:
var arrow3:Arrow = new Arrow();
arrow3.gotoAndStop(3);
arrow3.x = 220;
arrow3.y = 0;
stage.addChild(arrow3);
trace("Object: "+arrow3.name);
arrows.push(arrow3);
break;
case 3:
var arrow4:Arrow = new Arrow();
arrow4.gotoAndStop(4);
arrow4.x = 320;
arrow4.y = 0;
stage.addChild(arrow4);
trace("Object: "+arrow4.name);
arrows.push(arrow4);
break;
default:
}
}
function MoveArrows(){
for (var i:int = 0; i<arrows.length; i++){
arrows*.y+=arrow_speed;
var arrow_name = arrows*.name;
if (arrows*.hitTestObject(del)){
//removeChild(arrows*);
MovieClip(MovieClip(arrows*).parent).removeChild(arrows*);
//trace(arrow_name);
arrows.splice(i, 1);
}
}
}
function runMany(event:TimerEvent):void {
getTimer()/1000;
maxTime–;
}
function main(){
addEventListener(Event.ENTER_FRAME, Arrows);
//addEventListener(Event.ENTER_FRAME, MoveArrows);
gameTimer.addEventListener(TimerEvent.TIMER, runMany);
//Arrows();
}
main();
Now my problem is with this function:
function MoveArrows(){
for (var i:int = 0; i<arrows.length; i++){
arrows*.y+=arrow_speed;
var arrow_name = arrows*.name;
if (arrows*.hitTestObject(del)){
//removeChild(arrows*);
MovieClip(MovieClip(arrows*).parent).removeChild(arrows*);
//trace(arrow_name);
arrows.splice(i, 1);
}
}
}
if I use removeChild(arrows*); to get rid off the mc I get this error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
and if I use MovieClip(MovieClip(arrows*).parent).removeChild(arrows*); I get this error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@2f1ef99 to flash.display.MovieClip.
So where I’m doing it wrong?
Thanks for advance. =)