View Full Version : problem with a maze
la Swear
October 4th, 2007, 05:45 PM
forum friends,
I am a noob and the resources for AS3 aren't helping me much with this topic.
I want to:
control the bee with keyboard
make the maze walls boundaries the bee can't fly through
so far I have the keyboard control, but no clue about how to approach the maze. (everything I find is for as2...blah).
help?
I've included the .fla
I'd love to see someone's successful Flash 9/ as3 maze demo.
la Swear
October 4th, 2007, 09:42 PM
Updated File Structure with a separate .as file and document class in the .fla.
...Anyone?
forum friends,
I am a noob and the resources for AS3 aren't helping me much with this topic.
I want to:
make the maze walls boundaries the bee can't fly throughso far I have the keyboard control, but no clue about how to approach the maze. (everything I find is for as2...blah).
help?
I've included the .fla
I'd love to see someone's successful Flash 9/ as3 maze demo.
cranky crank
October 4th, 2007, 11:39 PM
onClipEvent(enterFrame){
movespeed = 4;
if ((Key.isDown(Key.RIGHT) || Key.isDown(68)) && !Hitting) {
_x+= movespeed;
}
if ((Key.isDown(Key.LEFT) || Key.isDown(65)) && !Hitting) {
_x-= movespeed;
}
if ((Key.isDown(Key.UP) || Key.isDown(87)) && !Hitting) {
_y-= movespeed;
}
if ((Key.isDown(Key.DOWN) || Key.isDown(83)) && !Hitting) {
_y+= movespeed;
}
//get bounds script
if (_root.walls.hitTest(getBounds(_root).xMax, _y, true)) {
_x--
Hitting = true;
} else if (_root.walls.hitTest(getBounds(_root).xMin, _y, true)) {
_x++
Hitting = true;
} else if (_root.walls.hitTest(_x, getBounds(_root).yMax, true)) {
_y--
Hitting = true;
} else if (_root.walls.hitTest(_x, getBounds(_root).yMin, true)) {
_y++
Hitting = true;
} else {
Hitting = false;
}
}
la Swear
October 5th, 2007, 06:23 AM
thank you for the code.
my code now reads like this:
(the playerBee collides with the maze)
//my code
package {
import flash.display.*;
import flash.text.*;
import flash.events.*;
public class Collide2 extends MovieClip {
public function Collide2() {
addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(event:Event) {
// test playerBee versus maze
if (playerBee.hitTestObject(maze)) {
messageText2.text = "hitTestObject: YES";
} else {
messageText2.text = "hitTestObject: NO";
}
}
//from keyboard
// initialize arrow variables
var leftArrow:Boolean = false;
var rightArrow:Boolean = false;
var upArrow:Boolean = false;
var downArrow:Boolean = false;
// set event listeners
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyPressedUp);
stage.addEventListener(Event.ENTER_FRAME, moveBee);
// set arrow variables to true
function keyPressedDown(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = true;
} else if (event.keyCode == 39) {
rightArrow = true;
} else if (event.keyCode == 38) {
upArrow = true;
} else if (event.keyCode == 40) {
downArrow = true;
}
}
// set arrow variables to false
function keyPressedUp(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = false;
} else if (event.keyCode == 39) {
rightArrow = false;
} else if (event.keyCode == 38) {
upArrow = false;
} else if (event.keyCode == 40) {
downArrow = false;
}
}
// move every frame
function moveBee(event:Event) {
var speed:Number = 5;
if (leftArrow) {
playerBee.x -= speed;
}
if (rightArrow) {
playerBee.x += speed;
}
if (upArrow) {
playerBee.y -= speed;
}
if (downArrow) {
playerBee.y += speed;
}
}
}
}
}
//kirupa code
onClipEvent(enterFrame) {
movespeed = 4;
if ((Key.isDown(Key.RIGHT) || Key.isDown(68)) && !Hitting) {
_x+= movespeed;
}
if ((Key.isDown(Key.LEFT) || Key.isDown(65)) && !Hitting) {
_x-= movespeed;
}
if ((Key.isDown(Key.UP) || Key.isDown(87)) && !Hitting) {
_y-= movespeed;
}
if ((Key.isDown(Key.DOWN) || Key.isDown(83)) && !Hitting) {
_y+= movespeed;
}
//get bounds script
if (_root.walls.hitTest(getBounds(_root).xMax, _y, true)) {
_x--
Hitting = true;
} else if (_root.walls.hitTest(getBounds(_root).xMin, _y, true)) {
_x++
Hitting = true;
} else if (_root.walls.hitTest(_x, getBounds(_root).yMax, true)) {
_y--
Hitting = true;
} else if (_root.walls.hitTest(_x, getBounds(_root).yMin, true)) {
_y++
Hitting = true;
} else {
Hitting = false;
}
I keep getting an error message that says this:
<strong>
1087: Syntax error: extra characters found after end of program.
I've attached the newest .zipped .fla - any ideas?
thanks!
SacrificialLamb
October 5th, 2007, 06:00 PM
i think you have 3 extra "}" just before the "//kirupa code"
la Swear
October 6th, 2007, 07:06 AM
i think you have 3 extra "}" just before the "//kirupa code"
saw that - thanks...
still not doing the trick (any takers?)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.