PDA

View Full Version : [AS2] Problem with flash game


Rockyeaster07
04-27-2012, 04:45 PM
Hi there, I'm creating a Spot the difference flash game, new to flash, i have 7 differences and i need to know how to make it so, when all 7 differences are clicked and have the circle it can go to the You win screen?

Prid
04-27-2012, 04:53 PM
Declare a variable in your Frame:

score = 0;

and then for each right difference found, in the button code for the difference, in the on(release) or on(press) (or even onRelease/onPress) part of the code, include an if statement, and increment the score variable:

score++;
if(score == 7){
_root.gotoAndStop("win_screen");
}

Tutorials to Read:
If Conditional (http://www.republicofcode.com/tutorials/flash/if_conditional/)

Rockyeaster07
04-29-2012, 05:03 AM
Sorry to be a total noob, but really unsure on this.. any other way to explain it for a noob?

xdeath
04-29-2012, 05:18 AM
Sorry to be a total noob, but really unsure on this.. any other way to explain it for a noob?
how he explained it was pretty basic. but i'll take a shot at explaining it.

ok so its a spot the difference game right? well lets say everything that is considered a "difference" will be a movieclip or a button placed on the stage.
so you have 7 differences, 1 movieclip/button for each difference. that makes 7 total.

following me so far? now what Prid was trying to tell you was there two ways of doing this. you can click on each movieclip/button and place the code on there or you can simply do it all on the main timeline. depending on how you choose to do it depends on how you write the code for its pressed.

see if you click the button/movieclip and press F9 to enter code then you'll have to use this for when its pressed:

on(press){
// do something
}


if your doing it all on the main timeline and not on the buttons directly. then you'll do it like this:

/*
when you place the movieclip/button on the stage
click it and give it an instance name. assuming you
had called one of them difference1. then this is how
you'd write it:
*/
difference1.onPress = function(){
// do something
}


now looking at Prids post you should understand it much better. so lets look at it. he want you to your frame (meaning on the main timeline) and place that variable there.

then on the movieclips/button if you put the code in a press event like i did above you can enter his code in there and it will work like a charm. so did that clear things up for you?

Rockyeaster07
04-29-2012, 12:04 PM
on(release)
{
this.gotoAndStop(2);
_root.spots_Left --;

}

I have the variable set up on the frame, ^ that is the code for my button atm which is working fine, but not sure how to add the code prid has given? Sorry to be a complete noob, i started flash like 1 week ago. Cheers.

xdeath
04-29-2012, 12:56 PM
not that its relevant but if you just started learning flash why on earth learn as2? as3 is better in pretty much every way.

as for prid's code it should look like this:

on(press){
_root.score++;
if(_root.score == 7){
_root.gotoAndStop("win_screen");
}
}


i normally use as3. but that should work.

Rockyeaster07
04-29-2012, 04:15 PM
This is what i have set up.

Dynamic Text - gyazo.com/cd1d2312dbd3316cc0e8ac17941538eb
Frame - gyazo.com/286e83461edf58d33c847cb1ef340bc3
Button - gyazo.com/f9af9104c0458561c604fe01695ae5c8

I have no compile errors, but it just doesn't work, when the button is clicked the red circle i have for the difference shows up, but the dynamic text doesn't go down if you get what im getting at... Anyone know why?

Rockyeaster07
04-29-2012, 06:29 PM
Anyone?

PasD
04-30-2012, 12:01 PM
not that its relevant but if you just started learning flash why on earth learn as2? as3 is better in pretty much every way.

as for prid's code it should look like this:

on(press){
_root.score++;
if(_root.score == 7){
_root.gotoAndStop("win_screen");
}
}


i normally use as3. but that should work.
hes a total noob. Its easier for noobs to learn as2 than as3. As2 is perfectly suited for creating noob games like spot the difference. As3 is too verbose, its more for applications and complex games.

PasD
04-30-2012, 12:03 PM
Anyone?
why when your score is == 0 you gotoAndStop(3). what is frame 3?

xdeath
05-01-2012, 08:11 AM
hes a total noob. Its easier for noobs to learn as2 than as3. As2 is perfectly suited for creating noob games like spot the difference. As3 is too verbose, its more for applications and complex games.
i started off with as2. but found as3 allowed me to grow so much in terms of coding. even if i wasn't using classes. in actual fact though if your running code from all these different places in as2 and you have to refer to it that can get very confusing.

back when i used it. i found myself having to stop and think about it. were with as23 alot of those basics are just no brainers. everyones entitled to there opinions. but i simply stating if your going to learn something i figured the logical thing to do would have been learn the better language if the person had access to it.