ActionScript 3.0 Game Programming
how to make outline in matching game
Submitted by elen on Mon, 07/26/2010 - 07:21.how to make the outline beside the rectangle card when the 2 cards is match correctly.
Thanks.
Publishing problems: No sound
Submitted by cosmosangel on Sun, 07/25/2010 - 17:28.Hi. I hope someone can help me out because this is driving me crazy. I have a Flash CS4 game based on the Air Raid game that I would like to add to the web site I am building in Dreamweaver CS4. The game has a music sound loop and other sound effects that play great in Flash, and when I open the SWF file alone. However, when I try to import the game into Dreamweaver to test it, the game is still playable but the sound dissappears. I followed the publishing settings shown on page 35, but obviously I am missing something. Is it connected to the HTML page generated by the publisher?
Thanks!
Additional feature to the match game
Submitted by Zaknaphein on Sun, 07/25/2010 - 02:41.So I just got done with the Match game part of the book and one thing that I wanted to add, to dabble a litle, was a timer that would turn the cards over automatically if a match was not found. However, the second card never turns face up. The game just pauses for a second, like its supposed to, and then the first card is turned back face down. Also, the trace statement that outputs what card was clicked doesn't execute until the first card is turned back face down. Below is the code that I've got with the additions that I made to the book code being in bold. Anyone have any thoughts on how to get this working? Thanks!
public function clickCard(event:MouseEvent){
var thisCard:Card = (event.currentTarget as Card);
trace(thisCard.cardFace); // test which card is selected
if (firstCard == null){ // first card in a pair
firstCard = thisCard;
firstCard.gotoAndStop(thisCard.cardFace + 2); // turn it over
} else if (firstCard == thisCard) { // clicked the first card again
firstCard.gotoAndStop(1); // turn back over
firstCard = null; // starting back over in state 1
} else if (secondCard == null) { // second card in pair
secondCard = thisCard;
secondCard.gotoAndStop(thisCard.cardFace + 2); // turn it over
// compare the two cards to see if they match
if (firstCard.cardFace == secondCard.cardFace){
//remove the match
removeChild(firstCard);
removeChild(secondCard);
// reset selection
firstCard = null;
secondCard = null;
} else { // the two cards didn't match
// setup our timer for delay
var lastTime:int = 0;
lastTime = getTimer(); // time since the Flash player started
var timeWaited:int = 0;
// makes the game pause for 1 second before turning over
do{
timeWaited = getTimer() - lastTime;
} while (timeWaited < 1000);
firstCard.gotoAndStop(1);
secondCard.gotoAndStop(1);
firstCard = null;
secondCard = null;
}
} else {
//reset the previous pair
firstCard.gotoAndStop(1);
secondCard.gotoAndStop(1);
secondCard = null;
// select first card in the next pair
firstCard = thisCard;
firstCard.gotoAndStop(thisCard.cardFace + 2);
}
} // end clickCard method
help with mouse detection
Submitted by calyston00 on Sat, 07/24/2010 - 16:13.Hi everyone, im really beginning in actionscript 3, so here we go : im trying to do a shooter kind of game that you have a hero at the bottom that can move left and rigth and you also use the mouse to shoot. But here si my problem (there many in the code).
I want the hero to move left and rigth, no problem thats nailed, but i want the hero to face left if the mouse is a certain amount of pixels from is ex and the same thing rigth. But my code here work with the left but when he go to the rigth it inverse the value ???? dont know why. Also the code always loop the animation if i do not move the mouse!!!! Here my code please somebody help me!!!!
var Key:KeyObject = new KeyObject(stage);
Mouse.hide();
var hs:Number=5;
var limitRight:Number=hero.x+hero.width+100;
var limitLeft:Number=hero.x-50;
//adding de target cursor
var Cible:MovieClip = new cible();
Cible.x=mouseX;
Cible.y=mouseY;
addChild(Cible);
//playing with cloud & adding mouse
var cloudSpeed:Number=2;
var cloudSpeedVar:Number=2;
stage.addEventListener(Event.ENTER_FRAME,onEnter);
function onEnter(e:Event):void
{
//playing with the mouse for target
Cible.x=mouseX;
Cible.y=mouseY;
trace(mouseX);
//adding cloud
smallCloud.x -=cloudSpeed;
smallCloud2.x -=cloudSpeed;
if(smallCloud.x < -295)
{
smallCloud.x = 555;
smallCloud.y = Math.random()*4;
cloudSpeed=Math.random()*cloudSpeedVar;
}
if(smallCloud2.x < -780)
{
smallCloud2.x = 780;
smallCloud2.y = Math.random()*4;
}
//controlling the hero
if (Key.isDown(Key.A))
{
hero.scaleX = 1;
hero.x -= hs;
hero.gotoAndStop('walk');
}
else if(mouseX
Issue with Picture Trivia Game
Submitted by margosi on Fri, 07/16/2010 - 19:16.After I open the Picture Trivia Game in either Flash CS4 or CS5 and try to Test or Run the game (without doing a thing to the code) I am getting two errors with the .as files. These are PictureTriveaGame.as, Line100 1023:incompatible override and PictureTriveaGame.as, Line100 1021: Duplicate function definition.
Note: It works ok in CS3, however I do not want to work on CS3 anymore.
Any suggestions?
Thanks!!
How to separate Matching game into 2 block
Submitted by elen on Wed, 07/14/2010 - 07:02.hi, i would like to know how to separate the matching into 2 blocks which is 1 block of word and 1 block of picture. The card of word(hat) match with the picture(hat).
Platform Game Question
Submitted by WEich1213 on Fri, 07/09/2010 - 22:35.Hello,
I'm trying to make a platform game like the one in the book, but it has no walls. And I want to keep the enemies from falling off of the platforms when they start walking when the game starts. I tried a few different things with no luck, so I was wondering if anyone knew how I could do it. I want the enemies on the upper platforms to turn around when they get near the edge of the platform. Any suggestions? I tried hitTestPoint to see if a point 5 pixels to the right and down from the enemy was not colliding with anything and if it wasn't then, turn around, but it didn't work. I got an error that said Error #1006: hitTestPoint is not a function. Here's the code I tried:
for(var j:int=enemies.length-1;j>=0;j--) {
var newHitPoint = new Point(enemies[j].x+5,enemies[j].y+5);
for(i=0;i
Platform Game Big Probs
Submitted by WEich1213 on Sat, 07/03/2010 - 18:03.I'm trying to make a platform game based on the one in the book, but I cant' get the characters, hero and enemies in the fla to respond to the as file. I have the name in the document class field. I have the Start Platform game and game level in the game frame on the fla file. I have the gamelevel and hero instance names in the instance name fields. Has anyone else had a prob. like this? I don't know what I'm doing wrong. Thanks
Problems with hitTestObject
Submitted by roestigraben on Mon, 06/21/2010 - 19:57.Hi all,
I am trying to do a game originally taught by Gary on Game University. Now, of course I wanted to expand and have now a problem with the hitTestObject method.
the error code is
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at CatchingGame/moveObjects()
the code where it happens is : (if I comment this code out, then it works (however, it does not detect collisions anymore)
I believe it could be that at a certain moment the array is empty and I still try to do the hitTestObject check.
Can you please help
BR
Peter
// loop to go thru the bullets array and thru the objects array
for(var l:int=bullets.length-1;l>=0;l--) {
for(var m:int=objects.length-1;m>=0;m--) {
if (objects[m].hitTestObject(bullets[l])) {
if (objects[m].typestr == "bad") {
score += 2;
good = new goodShot();
good.x = objects[m].x+25;
good.y = objects[m].y;
addChild(good);
oneSecond();
var myChannel1:SoundChannel = goodS.play();
} else {
score -= 2;
bad = new badShot();
bad.x = objects[m].x+25;
bad.y = objects[m].y;
addChild(bad);
oneSecond1();
var myChannel3:SoundChannel = badS.play();
}
removeChild(bullets[l]);
bullets.splice(l,1);
removeChild(objects[m]);
objects.splice(m,1);
if (score < 0) score = 0;
scoretxt = String(score);
scoreDisplay.text = scoretxt;
}
}
}
Help with expanding Catching Game
Submitted by Mrepic on Fri, 06/11/2010 - 01:20.I need help with the Catching Game from here:
http://flashgameu.com/podcast/flashgameu_com_video_tutorial_catching_gam...
I want to expand it so that it will drop three different type of objects. 1 being the "good", 2 being the "bad", and three being the "health".
The following is from line 50 to 69, which is where the coding isn't working.
var healthObjects:Array = ["Health1","Health2"]
if (Math.random() < .5) {
var r:int = Math.floor(Math.random()*goodObjects.length);
var classRef:Class = getDefinitionByName(goodObjects[r]) as Class;
var newObject:MovieClip = new classRef();
newObject.typestr = "good";
} else {
r = Math.floor(Math.random()*badObjects.length);
classRef = getDefinitionByName(badObjects[r]) as Class;
newObject = new classRef();
newObject.typestr = "bad";
} else {
r = Math.floor(Math.random()*healthObjects.length);
classRef = getDefinitionByName(healthObjects[r]) as Class;
newObject = new classRef();
newObject.typestr = "health";
I get the following error: 1083: Syntax error: else is unexpected.
So what should I be using instead of else? I have tried else if but that hasn't worked either. =(
Thank you!
Copyright Gary Rosenzweig
