ActionScript3 Code Help
Copy link to clipboard
Copied
Hi, I am new actionscript, but need help with some particular code. I have watched tutorials on Youtube, and followed this particular one: Flash CS6 Tutorial - Super Simple Avoider Game Part 5 - YouTube
I am trying to make a simple-avoider game where the goal is to collect a certain type of object, while dodging three other types of objects:
The objects are contained in this array:
var:objects Array = [new BlueBird(),new RedBird(),new Goomba(),new Ham()]
// objects[0] = Is a Blue Bird which jumps to scene 3 ("Death Scene")
// objects[1] = Is a Red Bird which jumps to scene 3 ("Death Scene")
// objects[2] = Is a Goomba which jumps to scene 3 ("Death Scene")
// objects[3] = Is an piece of Ham which adds Points
This is an if/ else if statement that I cannot get to work:
if((Pig.hit).hitTestObject(objects[objectsIndex])) { // Reset objects to y positions objects[objectsIndex].x = randomRange(0,3) * 50 objects[objectsIndex].y = -50; stage.removeEventListener(KeyboardEvent.KEY_DOWN,pressedButton); stage.removeEventListener(Event.ENTER_FRAME,CollisionSensor); stage.frameRate = 24; gotoAndStop(1,"GG WP"); //trace ("you died!"); }else if((Pig.hit).hitTestObject(objects[objectsIndex]) && objectsIndex == 3) { score = score + 1; //increase score by 1 point text1.text = String(score); // Score is now a string value // Since text1 is a text box, it must be denotated as a string // Reset the objects to y positions objects[objectsIndex].x = randomRange(0,3) * 50; objects[objectsIndex].y = -50 }
I cannot seem to get the objects[3] to accumulate points when it is hit.
Copy link to clipboard
Copied
what you posted would trigger errors unless there's other code you failed to post.

