-
[F8] ActionScript help
Hello
I thought I should post this here instead of the ActionScript-boards.
I'm making an adventure game and I'm trying to find out how to make a button with a command like "if been in frame X goto frame Y, if not been in frame X goto frame Z". Is this possible?
Here's an example how it would work in my game:
Guy goes to a bar and receives a beer (frame X)
A person asks the guy for a beer, if the guy has a beer the person gives him a clue (frame Y), if the guy doesn't have a beer the person doesn't tell the guy anything (frame Z).
I hope you understand what I'm trying to do.
EDIT: Also, do you know any good IRC-channels/servers for asking these types of questions?
Last edited by MrXX; 07-09-2007 at 07:15 AM.
-
When in doubt ask
Please try this code which is working for me.
Code:
var a=_currentframe;
var fx=2;//say.
var fy=3;//say.
var fz=4;//say.
if(a==fx){
gotoAndStop(fy);
}else{
gotoAndStop(fz);
}
trace(_currentframe);
stop();
<signature removed by admin>
-
I couldn't get it to work, here's my .fla:
http://www.wikiupload.com/download_page.php?id=174588
(I'm trying to force the user to click the red circle first before clicking the purple one, if the user clicks purple one before red he gets a stop-sign, if he has clicked red before purple he receives a green text)
New question: Let's say my guy goes into that bar frame and receives a beer. I want a beer icon to appear to bottom of the screen in every frame. How do I do that?
Last edited by MrXX; 07-09-2007 at 08:09 AM.
-
hey there
first of all I couldnt download your .fla file, but anyway, for your first question regarding X, Y, Z frame jumps what EagerBeaver said is somehow correct, the idea is to use the movie clip _currentframe property to find out where the current position is and using an if statement go to your desired location.
your second question about displaying the beer icon on the screen, just create a beer movie clip and put it on a layer and give it an instance name, then create a variable in your action script called bBeer and set it to false. then create a function that checks if the beer is collected by the user.
let me try showing some AS:
Code:
var bBeer:Boolean = false;
function checkBeer(bBeer){
if(bBeer == true){
Beer_mc._visible = true;
}else{
Beer_mc._visible = false;
}
}
create this on your main timeline, and preferably on frame 1 then all you need to do is just call the function whenever you need to change the state; for instance, first call it on its frame 1
and call it again when the user recieves the beer
I hope this helps, i know it might be a bit confusing but its much better to learn than just copy some code
please ask any questions you might have!
Ameretat
-
To Ameretat:
Thank you for your help, I understand that code and the purpose of it, but I have few questions:
-What should my beer movie clip/instance name be? Beer, bBeer, Beer_mc?!
-Where do I put this code, 1st frame, Beer movie clip, inventory layer?
Code:
var bBeer:Boolean = false;
function checkBeer(bBeer){
if(bBeer == true){
Beer_mc._visible = true;
}else{
Beer_mc._visible = false;
}
}
-Do I put the checks to frames or buttons?
EDIT: oh, and here's a new download link http://tiny url.com/345zl7 (remove space). I have tried to combine both of my problems to this single .fla
Last edited by MrXX; 07-09-2007 at 09:52 AM.
Reason: new link
-
I got the beer thing working! Now is it possible to make buttons, instead of movie clips, disappear? That way I wouldn't need the X,Y,Z frame checking.
-
good that you got it working.
yes, you can also make buttons disappear, both buttons and movie clips support a properties called _visible which controls the visibility of the object at run time. so you can easily reference to a button and set its _visibile to false or true.
Hope that helps
Ameretat
-
Originally Posted by Ameretat
yes, you can also make buttons disappear, both buttons and movie clips support a properties called _visible which controls the visibility of the object at run time. so you can easily reference to a button and set its _visibile to false or true.
Thanks for the help again, but I can't seem to get this to work.
I have a button named 'Getbeer' and a mc called 'Beer'
This is in my frame 1
Code:
stop();
var cGetbeer:Boolean = false;
function checkGetbeer(cGetbeer){
if(cGetbeer == true){
Getbeer._visible = false;
}else{
Getbeer._visible = true;
}
}
var cBeer:Boolean = false;
function checkBeer(cBeer){
if(cBeer == true){
Beer._visible = true;
}else{
Beer._visible = false;
}
}
This in beer getting frame
Code:
checkBeer(true);
checkGetbeer(true);
This in giving away beer frame
Code:
checkBeer(false);
checkGetbeer(false);
The beer dis/appears fine but the Getbeer button is visible all the time.
-
Learning Flash
I suggest separating setting of the flag and the visibility, because it seems that changing the visibility only works when that mc is being displayed (please correct me if this is wrong). This is a problem for the button, because it's only present in one frame.
eg (just for the button)
Code:
var cGetbeer:Boolean = false;
function checkGetbeer(){
if(cGetbeer == true){
Getbeer._visible = false;
}else{
Getbeer._visible = true;
}
}
In all frames with the button in it, use this:
To change the state (eg. I guess when you've already got the beer, and don't want to show the button anymore):
The attachment is based on your previous fla (I made the instance name of the button be "Beer2_mc", because it didn't seem to have one...).
HTH
Brendan
code tested in Flash Basic 8 (AS2), Windows XP
-
yes, one thing to remember when coding in Flash is that, each keyframe presents a new instance of the object, so unless you copy the key frames over, you will have to add the code to the new keyframe.
Ameretat
-
Thank you yow and Ameretat, that worked
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
|