Forum Topic: AS3 Help : if Condtion wont work :(

(109 views • 9 replies)

This topic is 1 page long.

<< < > >>
Mad as Hell

asdqwe2311

Reply To Post Reply & Quote

Posted at: 11/7/09 05:15 AM

asdqwe2311 NEUTRAL LEVEL 02

Sign-Up: 01/21/08

Posts: 39

What else i can do? i just made a text like this :
in frame 1 :
stop();
if (Keyis.DOWN(Key.DOWN)) {
gotoAndStop(2);
}
in frame 2 :
if (Keyis.UP(Key.DOWN)) {
gotoAndStop(1);
}
----
What's wrong with this Text?
it's just wont work, what i really want to do is to when i press the Down Botton it goes to the next frame wich it has Swinging sword(i wanna do a swing sword when hit down botton)and it just didnt work, Any ideas?
no errors found while testing the Syntax.


None

liaaaam

Reply To Post Reply & Quote

Posted at: 11/7/09 06:01 AM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,533

The problem is that you're only checking the key state (if they down key is pressed) once per frame - when the frame is loaded, in fact. You need to check this every frame, thus you need an event listener. In AS2 this is very simple - look up "onEnterFrame" or perhaps "onKeyDown".. and other such things.


None

asdqwe2311

Reply To Post Reply & Quote

Posted at: 11/7/09 06:09 AM

asdqwe2311 NEUTRAL LEVEL 02

Sign-Up: 01/21/08

Posts: 39

Ah, well, could you Geanerate me the Syntax?
like what i say : when key is Down (key Down) goto and stop on frame 2
when the key is up (unpressed) (key Down) return to frame 1.
is it possible to go like this motto?


None

grafik2d

Reply To Post Reply & Quote

Posted at: 11/7/09 07:56 AM

grafik2d NEUTRAL LEVEL 10

Sign-Up: 06/29/04

Posts: 165

first of Key.isDown isn't part of AS3, if you want to use AS3 you need to use event listeners like this

stage.addEventListener(KeyboardEvent.KEY _DOWN , checkKeys);
stage.addEventListener(KeyboardEvent.KEY _UP, keyUps);

function keyUps(event:KeyboardEvent) {
if (event.keyCode == 39) {
event.keyCode = 0;
varRight=false;
trace("Right key is NOT down");
}
if (event.keyCode == 38) {
event.keyCode = 0;
varUp=false;
trace("Up key is NOT down");
}

function checkKeys(event:KeyboardEvent){
if (event.keyCode == 39) {
trace("Right key is down");
varRight = true;
}
if (event.keyCode == 38) {
trace("Up key is down");
varUp = true;
}

If you want to go with As2 then you can do this

this.onEnterFrame=function(){
myFunctionName();
}

function myFunctionName(){
if(Key.isDown(someKeycode)){
do this
}else{
do that
}
}


None

asdqwe2311

Reply To Post Reply & Quote

Posted at: 11/7/09 09:03 AM

asdqwe2311 NEUTRAL LEVEL 02

Sign-Up: 01/21/08

Posts: 39

At 11/7/09 07:56 AM, grafik2d wrote: first of Key.isDown isn't part of AS3, if you want to use AS3 you need to use event listeners like this

stage.addEventListener(KeyboardEvent.KEY _DOWN , checkKeys);
stage.addEventListener(KeyboardEvent.KEY _UP, keyUps);

function keyUps(event:KeyboardEvent) {
if (event.keyCode == 39) {
event.keyCode = 0;
varRight=false;
trace("Right key is NOT down");
}
if (event.keyCode == 38) {
event.keyCode = 0;
varUp=false;
trace("Up key is NOT down");
}

function checkKeys(event:KeyboardEvent){
if (event.keyCode == 39) {
trace("Right key is down");
varRight = true;
}
if (event.keyCode == 38) {
trace("Up key is down");
varUp = true;
}

If you want to go with As2 then you can do this

this.onEnterFrame=function(){
myFunctionName();
}

function myFunctionName(){
if(Key.isDown(someKeycode)){
do this
}else{
do that
}
}

oh, could you Explain me what does Listner means? does it means an Effect or a Condtion?
this Really look like AOE2 Triggers or something, and i've used to work out with them.


None

asdqwe2311

Reply To Post Reply & Quote

Posted at: 11/7/09 09:08 AM

asdqwe2311 NEUTRAL LEVEL 02

Sign-Up: 01/21/08

Posts: 39

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: ')' or ',' expected
stage.addEventListener(KeyboardEvent.KEY _DOWN, checkKeys);

Total ActionScript Errors: 1 Reported Errors: 1


None

Joelasticot

Reply To Post Reply & Quote

Posted at: 11/7/09 09:39 AM

Joelasticot EVIL LEVEL 37

Sign-Up: 02/14/03

Posts: 868

At 11/7/09 09:08 AM, asdqwe2311 wrote: **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: ')' or ',' expected
stage.addEventListener(KeyboardEvent.KEY _DOWN, checkKeys);

Total ActionScript Errors: 1 Reported Errors: 1

That's because Newgrounds breaks apart long strings. Remove the space from "KEY _DOWN"

var s=0;var p=0;addEventListener("enterFrame", function(){
s+=(25-p)/20;p+=Math.ceil(s);var o="";
for(var i=0;i<p;i++){o+=" ";};trace(o+"joelasticot");})

BBS Signature

None

YoinK

Reply To Post Reply & Quote

Posted at: 11/7/09 10:02 AM

YoinK LIGHT LEVEL 53

Sign-Up: 01/05/01

Posts: 6,094

I don't think it's a good idea to put if statements on separate frames.... it usually works better to have them on the same frame.

Kanye West Did What??????
They should make a black guy the manager, they know how to run shit!
2 Girls 1 Cup .... THE SONG!!!!


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 11/7/09 10:21 AM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,585

At 11/7/09 10:16 AM, YavonnaHugstand wrote: Gosh, that's loads simpler than AS2

AS3 is more complicated but better, fact. Its not that hard getting the hang of it

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

henke37

Reply To Post Reply & Quote

Posted at: 11/7/09 01:18 PM

henke37 NEUTRAL LEVEL 23

Sign-Up: 09/10/04

Posts: 3,604

as 2: breif, messy, hard to debug, insane event system, evolved into what it is today
as 3: descriptive, easy to debug, easy event system, clearly designed with the full system in mind from the start.

Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.


All times are Eastern Standard Time (GMT -5) | Current Time: 11:47 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!