-
Visabilty 0 when a score is reached?
Hi guys im working on a very basic rpg (with blocks and circles) just to get experience in doing things with variables and such, a learning experience none the less
what i have is a magic button that when pressed heals your character and subtracts 3 from the magic power
Actionscript Code:
on (release) { health += random(153); } on (release) { mag -= (3); } on (release) { gotoAndPlay (2); }
it heals a random 0-153 which i like, however! once the total magic gets down to like 2 you shouldnt be able to click it anymore seeing as it costs more than you have! Instead it just goes down into the negatives. Is there anyway to stop both of these from happening?
in the frame that this will return to after the animation is complete i have this script
actionscript Code:
if (_root.mag <=0) removeMovieClip("sub");
but it does nothing and also claims there are no errors ((the magic button is named sub i am not sure why i named it that...))
Thanks for reading!
Last edited by Ecuder; 05-29-2010 at 12:05 AM.
How can you say so much, but say so little?
-
When you know are.
On the button you should have something like this...
Actionscript Code:
on (release) { if ( mag >= 3) { health += random(153); mag -= 3; gotoAndPlay (2); } }
Although what you have works, you only need one "on release" per button.
So basically all you need is an "if statement" that says "if mag is more than or equal to 3, go ahead and execute this bit of code". You could also do "if ( mag > 2)", but the >= 3 makes more sense because it's the same number that's subtracted from your mag variable.
Does that make sense?
About the button removal, the code to remove the button is on the same timeline with the button on it as well? Keep in mind that you have to target the button based on the path to get to it.
I see you're using _root.mag in the removal part when you're not using _root.mag in the other one, it's possible that you're referring to the wrong variable. An easy way to test if your variables are doing what you want to do is to use traces. For instance...
Actionscript Code:
if (_root.mag <=0) { removeMovieClip("sub"); trace("_root.mag: " + _root.mag); // this will write "_root.mag" + a number in the output window
If you're getting something like "_root.mag: undefined" then it'll be obvious you're aiming at the wrong variable, one that doesn't exist.
You can do a trace("mag" + mag ) on the button to see if it's giving you the right number as well.
And beyond that, try "sub.removeMovieClip()". I haven't used AS2 in a while, but I usually used the dot when doing removeMovieClip, not sure if you have to or not.
-
Senior Member
He seems to be following AS1 syntax, which often still works in AS2 "mode".
Ecuder: Don't learn AS1. You will be at a disadvantage.
-
Originally Posted by Ray Beez
He seems to be following AS1 syntax, which often still works in AS2 "mode".
Ecuder: Don't learn AS1. You will be at a disadvantage.
What would this same code look like in as2?
>and yes this did work in my version of Flash mx2004
How can you say so much, but say so little?
-
When you know are.
Ray Beez was just referring to your use of...
sub.removeMovieClip(); would be the AS2 way of doing it. Both would work, but it's nicer to do it the AS2 way.
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
|