OK, I have another problem, a rather gamebreaking one. It crashes.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at cowsNEW3_fla::MainTimeline/hitTest()
The problem is with the last function in the code, BUT I DON'T KNOW WHAT THE PROBLEM MEANS. It keeps referencing line 187, which is the one containing the removeChild of the tempMissile.
stage.addEventListener(MouseEvent.CLICK,beginlaunch);
var score:int = 0
output.text = String(score)
var benny = new gamesong()
var changame : SoundChannel;
changame = benny.play();
stage.addEventListener(Event.ENTER_FRAME, onframe)
var shiphit = new shipbox()
var launched = false;
var cowinair = false
var gamecow = new cowlaunch();
var stopalien = false
var failtimer = new Timer(15000)
var cowtimer = new Timer(400)
var cowtimerfinished = false
var ready = true
var forcefire = false
var makerespawnwork = true
var aim = new cowhit()
this.addChild(aim);
aim.startDrag(true,new Rectangle(0,0,1500,1500));
aim.alpha = 0
cowtimer.addEventListener(TimerEvent.TIMER, cowtimerevent)
function beginlaunch(event:MouseEvent) {
if (cowinair == false){
if (launched == false){
gamecatapultarm.play();
gamecatapultwinder.play() ;
gamecatapult.play();
stage.addChild(gamecow);
gamecow.x = 1493.6;
gamecow.y = 534.25;
gamecow.alpha = 100
gamecow.play();
var cowtimergo = true
launched = true;
cowtimer.start()
trace("begin launch sequence");
var ready = false
makerespawnwork = false
}
else{
trace("launch failure")
}
}
}
function cowtimerevent(e:TimerEvent){
cowtimerfinished = true
cowtimer.stop()
forcefire = true
}
stage.addEventListener(MouseEvent.CLICK,launchcow);
var tempMissile = new flingablecow
var removertimer = new Timer(4500)
function launchcow(event:MouseEvent) {
if (launched == true) {
if (cowinair == false){
if (cowtimerfinished == true) {
if (makerespawnwork == false) {
addChild(tempMissile)
gamecow.stop()
tempMissile.rotation = 45 + gamecatapultarm.arm.rotation
tempMissile.x = gamecow.x + gamecow.thecow.x
tempMissile.y = gamecow.y + gamecow.thecow.y
tempMissile.angle=Math.atan2 (aim.y-tempMissile.y,aim.x-tempMissile.x)
tempMissile.speed = 5
tempMissile.gotoAndPlay(2)
trace(tempMissile.angle);
removertimer.start()
removertimer.addEventListener(TimerEvent.TIMER, remover)
gamecow.alpha = 0
trace("FIRE AWAY!")
launched = false
cowinair = true
}
}
}
}
else{
trace("youfail")
}
}
stage.addEventListener(Event.ENTER_FRAME, cowfly)
function cowfly(event:Event) {
if (tempMissile.speed !=-1) {
tempMissile.x +=18*Math.cos(tempMissile.angle)
tempMissile.y +=18*Math.sin(tempMissile.angle)
}
}
removertimer.addEventListener(TimerEvent.TIMER, remover)
function remover(e:TimerEvent){
stage.removeChild(tempMissile)
removertimer.stop()
cowinair = false
stage.removeChild(gamecow)
makerespawnwork = true
}
var tempEnemy = new alienship()
tempEnemy.speed = -1
var timer = new Timer(100)
timer.start()
timer.addEventListener(TimerEvent.TIMER, addTester)
failtimer.addEventListener(TimerEvent.TIMER, gameover)
function gameover(e:TimerEvent){
gotoAndStop(1, "endscreen")
}
var enemyslope:Number;
function addTester(e:TimerEvent){
stage.addChild(tempEnemy)
trace("Enemy Enter")
tempEnemy.x= Math.random()*1000 + 100
tempEnemy.y= -200
tempEnemy.angle=Math.atan2 (475-tempEnemy.y,280-tempEnemy.x)
trace(tempEnemy.angle);
tempEnemy.speed=5;
timer.stop()
stage.addChild(shiphit)
shiphit.x = tempEnemy.x + 50
shiphit.y = tempEnemy.y + 50
shiphit.alpha=0
failtimer.reset()
failtimer.start()
}
function onframe(event:Event) {
if (tempEnemy.speed !=-1) {
tempEnemy.x +=5*Math.cos(tempEnemy.angle)
tempEnemy.y +=5*Math.sin(tempEnemy.angle)
shiphit.y +=5*Math.sin(tempEnemy.angle)
shiphit.x +=5*Math.cos(tempEnemy.angle)
}
}
failtimer.addEventListener(TimerEvent.TIMER, killalien)
function killalien(e:TimerEvent){
if (stopalien == true) {
stopalien = false
stage.removeChild(tempEnemy)
failtimer.stop()
stage.removeChild(shiphit)
}
}
addEventListener(Event.ENTER_FRAME, hitTest)
function hitTest(touch:Event):void
{
if (tempMissile != null)
{
if (shiphit.hitTestObject(tempMissile))
{
if(tempEnemy != null && !tempEnemy.dead && tempEnemy.stage != null)
{
trace("box hit")
stage.removeChild(tempEnemy)
tempEnemy.gotoAndStop(1)
stage.removeChild(tempMissile)
cowinair = false
trace("they hit")
stage.removeChild(gamecow)
removertimer.stop()
score = score+50
timer.start()
output.text = score.toString()
makerespawnwork = true
stage.removeChild(shiphit)
failtimer.stop()
stopalien = false
}
else
{
trace("hit, does not exist")
}
}
}
}
stop();
And no, my teacher can't help me. I'm significantly beyond them.