Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-09-2011, 10:06 PM   #1
Corr500
Registered User
 
Join Date: Jan 2011
Posts: 5
Default [AS3] Trying to get enemy spawn

Hey I am very new to actionscript and making a basic fruit catcher game. Trying to get enemy spawn, know the code I have works for a friend, but in mine my file will load with no errors. Want my fruit to fall down the screen, but when it loads, nothing is there and nothing happens. My code:

Main:
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.events.TextEvent;
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.ui.Mouse;
import classes.*;// << imports all of the class files inside classes folder

public class Main extends Sprite {
public var enemy:Array;
private var A_apple:AC_apple;


private var timeRemainingate = new Date();
private var countDownTimer:Timer;

public function Main():void {
play_button.visible=true;
goBox.visible=false;
enemy = new Array();

var format:TextFormat = new TextFormat();
format.font="Times new Roman";
format.color=0xFF0000;
format.size=25;
format.leading=4;

timeBox = new TextField() ;
timeBox.defaultTextFormat=format;
timeBox.x=stage.stageWidth/2+20;// put it next to the static prompt text
timeBox.y=186;
timeBox.width=60;
timeBox.height=30;
timeBox.border=timeBox.background=false;//no border or background colour
timeBox.type=TextFieldType.INPUT;// allow user input
timeBox.maxChars=2;
timeBox.restrict="0-9";
stage.addChild(timeBox);
stage.focus=timeBox;



timeBox.addEventListener(KeyboardEvent.KEY_DOWN, startGame);
}


private function startGame(event:KeyboardEvent):void {
if (event.keyCode==Keyboard.ENTER) {
this.timeRemaining.time=int(timeBox.text)*1000;
play_button.visible=false;
timeBox.visible=false;
stage.removeEventListener(KeyboardEvent.KEY_DOWN,s tartGame);




countDown.text=convertTime(this.timeRemaining);

//Paul Vickers - textAndStuff
this.countDownTimer=new Timer(100,this.timeRemaining.time/100);
this.countDownTimer.addEventListener(TimerEvent.TI MER, tickTock);
this.countDownTimer.start();
this.countDownTimer.addEventListener(TimerEvent.TI MER_COMPLETE, endGame);
}
}
public function onTick(timerEvent:TimerEvent):void {

var newApple = new AC_apple (200, 15);
enemy.push(newApple);
addChild(newApple);

for each (var A_apple:AC_apple in enemy) {
A_apple.moveDownABit();
}


}

//Paul Vickers - textAndStuff
private function tickTock(e:TimerEvent) {
this.timeRemaining.time-=100;
this.countDown.text=convertTime(this.timeRemaining );
}

//Paul Vickers - textAndStuff
private function convertTime(tate):String {
var mm:String,ss:String,ms:String;
mm=t.minutes<10?"0"+t.minutes:t.minutes.toString() ;
ss=t.seconds<10?"0"+t.seconds:t.seconds.toString() ;

return mm+":"+ss
}

private function endGame(e:TimerEvent) {
countDown.visible=false;
goBox.visible=true;
}
}

}

Class Code:
package classes {

import flash.display.Sprite;



public class AC_apple extends Sprite {




// Initialization:
public function AC_apple(_x:uint, _y:uint) {
this.x = _x;
this.y = _y;
configUI();
}

public function moveDownABit():void
{
this.y = y + 3;
}


protected function configUI():void { }
}

}

There is alot of unnecessary code in their for my timer etc. Any help Much appreciated
Corr500 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:29 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.