ok I just wrote it on a notepad since I cannot test it, this goes on the main timeline, & does all the jobs so maybe you should not have any program written inside movieclips besides "stop();"
Somethings to check if there are still errors:
setinterval is written properly for as2?
movieclip linkage names are spelled correct case for the attachmovieclip?
If you still have an issue you can just take parts from the program and put it in yoursPHP Code://Share this with AS3.0 for help
var score = 0;
var check_interval=null
var check_time=1000//every 1000 milliseconds, check if fairy count is too low to spawn more
var check_enabled=false
var fairy_array = []
var fairy_death_spawn_array=[]
var fairy_death_duration=700//ms
var MAXFAIRY = 10;
var FAIRYINDEX=0
var playerSpeed=35
//Setings for the game
var SPEEDER = 6;
//positive speed for the fairy
var NEGSPEEDER = -6;
//negtive speed for the fairy
var LEFT = 0;
//x = 0
var TOP = 0;
//y = 0
var BOTTOM = stage.stageHeight-50
//y = 718
var RIGHT = stage.stageWidth-50;
//stop();
var current_depth=10;
init();
//spawn player and faries
current_depth++
attachMovie("Swatter", "Swatter", current_depth);
//var swatter_var:Swatter=new Swatter()
//stage.addChild(swatter_var);
//swatter_var.name="Swatter"
//attach the swatter
_root["Swatter"]._x = 300;
//swatter ccordinates
_root["Swatter"]._y = 200;
//swatter ccordinates
//Spawncap for the fairies
function init() {
fairy_array =[]
fairy_death_spawn_array=[]
SPEEDER = 6;
//positive speed for the fairy
NEGSPEEDER = -6;
//negtive speed for the fairy
LEFT = 0;
//x = 0
TOP = 0;
//y = 0
BOTTOM = Stage.height-50
//y = 718
RIGHT =Stage.width-50;
MAXFAIRY = 10;
FAIRYINDEX=0
//Spawncap for the fairies
//Fairy Array
///createEmptyMovieClip("fairy_spawn", 0);
//var fairy_spawn_var:Fairy=new Fairy()
//stage.addChild(fairy_spawn_var);
//fairy_spawn_var.name="fairy_spawn_var"
///movieclip where fairies spawn in
fairyinit();
}
function fairyinit() {
//settings for the fairies
FAIRYINDEX = 0;
//Set the current spawn to 0
while (FAIRYINDEX<MAXFAIRY) {
spawnFairy();
}
FAIRYINDEX=MAXFAIRY
//when the fairy number is below the spawn cap, spawn faries periodically. However, flash crashes when I try to use the interval, perhaps an issue with flash trying to cound how many movieclips are on the canvas and running the setInterval code at the same time
check_enabled=true
//check_interval=setTimeout(lowFairyCountCheck,check_time);
setInterval(lowFairyCountCheck, check_time);
}
function lowFairyCountCheck(){
if(check_enabled){
trace("check " + FAIRYINDEX)
while (FAIRYINDEX<MAXFAIRY) {
spawnFairy();
}
}
}
function spawnFairy() {
//Code for when the fairy is spawned. This determines the speed, the coordinates, and runs the function for the movement
// var fairy_spawn_var:Fairy=new Fairy()//create fairy variable
//stage.addChild(fairy_spawn_var);//add it to stage
//fairy_spawn_var.name="fairy_spawn_var"//give it a name to access as stage.getChildByName("fairy_spawn_var").x etc..
current_depth++;
attachMovie("Fairy", "Fairy"+current_depth, current_depth);
//trace(fairy_clip);
_root["Fairy"+depth_num].NEGVELX = Math.random()*NEGSPEEDER;
_root["Fairy"+depth_num].NEGVELY = Math.random()*NEGSPEEDER;
_root["Fairy"+depth_num].VELX = Math.random()*SPEEDER;
_root["Fairy"+depth_num].VELY = Math.random()*SPEEDER;
_root["Fairy"+depth_num]._x = Math.random()*RIGHT;
_root["Fairy"+depth_num]._y = Math.random()*BOTTOM;
//fairy_spawn_var.onEnterFrame = fairymove;
fairy_array.push( _root["Fairy"+depth_num]);//The fairy enemy
FAIRYINDEX++
}
onEnterFrame=function(){
for(var i=0;i<fairy_array.length;i++){
if (fairy_array[i].hitTest(Wall) == true) {
fairy_array[i]._x += fairy_array[i].VELX;
fairy_array[i]._y += fairy_array[i].VELY;
fairy_array[i]._x += fairy_array[i].NEGVELX;
fairy_array[i]._y += fairy_array[i].NEGVELY;
}else{
unloadMovie(fairy_array[i])//unload fairy that left the wall
fairy_array.splice(i,1)//remove fairy from array space
FAIRYINDEX--;//subtract the index so that more fairies missing can be added later if needed.
}
}
/*
if (this.hitTest(Wall) == false) {//The goal of the faries is to swat them down before they leave the field. Planning on having this deducting 3 points from the score.
unloadMovie(this);
}
*/
}
//Player Controls: WASD for movement, P for swatting
// A is 65
// S is 83
// D is 68
// W is 87
var Attack_Fairy:Object = new Object();
Attack_Fairy.onKeyDown = function() {
if (Key.getCode() == "80") {
Splat();
kill();
}
if (Key.getCode() == "87") {//w
_root["Swatter"]._y-=playerSpeed
}
if (Key.getCode() == "65") {//a
_root["Swatter"]._x-=playerSpeed
}
if (Key.getCode() == "83") {//s
_root["Swatter"]._y+=playerSpeed
}
if (Key.getCode() == "68") {//d
_root["Swatter"]._x+=playerSpeed
}
};
/*
stage.addEventListener(KeyboardEvent.KEY_DOWN,kd)
function kd(e:*){
if(e.keyCode=="80"){
Splat();
kill();
}
if(e.keyCode=="87"){//W
//Key.addListener(Attack_Fairy);
stage.getChildByName("Swatter").y -= playerSpeed;
}
if(e.keyCode=="65"){//A
//Key.addListener(Attack_Fairy);
stage.getChildByName("Swatter").x -= playerSpeed;
}
if(e.keyCode=="83"){//S
//Key.addListener(Attack_Fairy);
stage.getChildByName("Swatter").y += playerSpeed;
}
if(e.keyCode=="68"){//D
//Key.addListener(Attack_Fairy);
stage.getChildByName("Swatter").x+= playerSpeed;
}
}
*/
function kill(){
for(var i=0;i<fairy_array.length;i++){
if (fairy_array[i].hitTest(_root["Swatter"]) == true) {
//var fairy_death_spawn_var:Fairy_death=new Fairy_death()
//stage.addChild(fairy_death_spawn_var);
//fairy_death_spawn_var.name="fairy_death_spawn_var"
current_depth++
attachMovie("Fairy_death", "Fairy_death"+current_depth, current_depth);
fairy_death_spawn_array.push(_root["Fairy_death"+depth_num]);//The fairy enemy
_root["Fairy_death"+depth_num]._x=fairy_array[i]._x
_root["Fairy_death"+depth_num]._y=fairy_array[i]._y
//setTimeout(removeFairyDeath,fairy_death_duration) ------------------------------------------------------required
unloadMovie(fairy_array[i])//unload fairy that left the wall
fairy_array.splice(i,1)//remove fairy from array space
FAIRYINDEX--;//subtract the index so that more fairies missing can be added later if needed.
}
}
}
function removeFairyDeath(){
//while(fairy_death_spawn_array[0].name=="hit"){//---------------------------------------------------------required
//unloadMovie(fairy_death_spawn_array[0])//unload splat
//fairy_death_spawn_array.shift()
//}
if(fairy_death_spawn_array.length>0){
unloadMovie(fairy_death_spawn_array[0])//unload fairy death
fairy_death_spawn_array.shift()
}
}
function Splat() {
depth_num++
attachMovie("hit", "hit", depth_num);
//var hit_var:hit=new hit()//attach for as3
//stage.addChild(hit_var)//add to stage
//hit_var.name="hit"//give name
//hit_var._x = Swatter._x;
//hit_var._y = Swatter._y;
//hit_var.x = stage.getChildByName("Swatter").x;
//hit_var.y = stage.getChildByName("Swatter").y;
// fairy_death_spawn_array.push(_root["hit"]);//add to same array as fairy death for removing both at once later
}
//playSound(placeholder_DnB)
//playSound(Controls)
//function playSound(a){
//var snd:Sound=new a()
//snd.play()
//}
//SoundMixer.stopAll() //stop all sounds
/*
//soundtrack is a placeholder
// Play Sound Behavior
_global.Behaviors.Sound.placeholder_spunk.start(0, 1);
// End Play Sound Behavior
//Play Internal Sound Behavior
if (_global.Behaviors == null) {
_global.Behaviors = {};
}
if (_global.Behaviors.Sound == null) {
_global.Behaviors.Sound = {};
}
if (typeof this.createEmptyMovieClip == 'undefined') {
this._parent.createEmptyMovieClip('BS_placeholder_spunk', new Date().getTime()-(Math.floor((new Date().getTime())/10000)*10000));
_global.Behaviors.Sound.placeholder_spunk = new Sound(this._parent.BS_placeholder_spunk);
} else {
this.createEmptyMovieClip('_placeholder_spunk_', new Date().getTime()-(Math.floor((new Date().getTime())/10000)*10000));
_global.Behaviors.Sound.placeholder_spunk = new Sound(this.BS_placeholder_spunk);
}
_global.Behaviors.Sound.placeholder_spunk.attachSound("placeholder_DnB.mp3");
if (true) {
_global.Behaviors.Sound.placeholder_spunk.start(0, 1);
}
//End Behavior
*/
