-
Combination of certain position and pressing a key
Hi, I would like to make following situation: when movie clip arrives in certain position (_x), between 1390 and 1440, all application goes to the first frame (start). But, if MC arrived in that position and, in the same time, you pressed key UP - application did not go to the start, it just continues to play. I made following code:
onClipEvent (enterFrame) {
if(Key.isDown(Key.RIGHT)) {
_x = Math.max (-2900, _x - 10);
}
if(Key.isDown(Key.LEFT)) {
_x = Math.min (2700, _x + 10);
}
if(_x < 1440)
if(_x > 1390) {
_parent.gotoAndPlay("start");
}
if(Key.isDown(Key.UP))
if(_x < 1440)
if(_x > 1390) {
_parent.gotoAndPlay("start") == false;
}
}
But, it does not work. Application goes to the start in both cases. Does anyone know what`s the problem with that last step in my code (with key UP)? Is there some other solution maybe?
-
Senior Member
PHP Code:
_parent.gotoAndPlay("start") == false;
what is this supposed to do?
what it does is it 1) calls gotoAndPlay("start") - like you said, "goes to the start in both cases" - and then 2) tries to compare the returned value with "false" for no reason.
-
Yes, I know it does not work. So, I asked what do I need to change in my code. I explained what I want to make: when movie clip arrives in certain position (_x), between 1390 and 1440, all application goes to the first frame (start). But, if MC arrived in that position and, in the same time, you pressed key UP - application should not go to the start, it should continue to play.
-
Senior Member
what do I need to change in my code
ok, you need to change the line I quoted.
I explained what I want to make
I did not ask what the whole code is supposed to do, just this line.
-
I know I have to change the last step and I asked for help - What do I need to write insted of that wrong last step, or is there some other solution (to change whole code maybe with some other code?) If you don`t know the answer, or if you don`t want to help, please don`t waste your and my time. If you know the answer, please write me correct line for that last wrong step or some new code that could work. Thanks.
-
Code follows a logical sequence. In this case it runs from top to bottom.
if(_x > 1390 &&_x < 1440){
if(!Key.isDown(Key.UP)){
_parent.gotoAndPlay("start");
}
}
This is a simple way. The problem is it continues to check. If you want it to only check once you need to create a new variable that tracks it. Functions aren't variables and you shouldn't treat it like one. gotoAndPlay is an action. The only way you'd way to put a function in a check like what you have is if the function is suppose to return data.
-
hm...maybe I don`t know to explain the problem. Application should NOT go to the start if you press key UP...If you don`t press UP (and if MC is between 1390 & 1440), only in that case application should go to the start.
By pressing key UP you make your character to jump above barrier and to continue with application, If you don`t press key UP in that moment (when barrier is between 1390 & 1440) - character will falter and fall down and application goes back to the start.
-
Hey, it works ! It seems that sign "!" in front of Key.is Down is the right solution. Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|