Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-02-2012, 10:50 PM   #1
SolomonM
Registered User
 
Join Date: Mar 2012
Posts: 9
Default Does anybody know why this code does not work?

Does anybody know why this code does not work?

ActionScript Code:
if (bar1.currentFrame == 1)                 {                     bar1.gotoAndStop(2);                 }                 if (bar1.currentFrame == 2)                 {                     bar1.gotoAndStop(3);                 }                 if (bar1.currentFrame == 3)                 {                     bar1.gotoAndStop(4);                 }                 if (bar1.currentFrame == 4)                 {                     bar1.gotoAndStop(5);                 }                 if (bar1.currentFrame == 5)                 {                     bar1.gotoAndStop(6);                 }

Last edited by SolomonM; 04-02-2012 at 10:52 PM.
SolomonM is offline   Reply With Quote
Old 04-02-2012, 11:06 PM   #2
iamgotenks
Super Saiyan
 
iamgotenks's Avatar
 
Join Date: Nov 2011
Location: New Zealand
Posts: 335
Default

does it just not work? or does it just go to frame 6?
iamgotenks is offline   Reply With Quote
Old 04-03-2012, 12:31 AM   #3
bowljoman
Senior Member
 
Join Date: Jan 2008
Posts: 831
Default

I would rather

ActionScript Code:
if(bar1.currentFrame<=5)     bar1.gotoAndStop(bar1.currentFrame+1);
__________________
i = (Andy)this;

Last edited by bowljoman; 04-03-2012 at 12:45 AM.
bowljoman is offline   Reply With Quote
Old 04-03-2012, 12:43 AM   #4
iamgotenks
Super Saiyan
 
iamgotenks's Avatar
 
Join Date: Nov 2011
Location: New Zealand
Posts: 335
Default

to advance to the next frame, you can use bar1.nextFrame();
iamgotenks is offline   Reply With Quote
Old 04-03-2012, 03:35 AM   #5
m1990
Registered User
 
Join Date: Apr 2012
Posts: 2
Default

I am no expert by any means, and this is just a guess. However, I am currently in a flash class at my college and if I'm recalling correctly, a classmate made a comment regarding using multiple "if"s in the same way. I believe my professor said you would need to use "else if"s instead of continually using "if". Not sure if that is right or makes sense but it's worth a shot. Hope it works. If not, I tried =) Maybe the link below would help?

.............
{help.}
{adobe.}
{com/}
{en_US/ActionScript/}
{3.0_ProgrammingAS3/}
{WS5b3ccc516d4fbf351e63e3d118a9b90204-7fce}
{.html}

(take out curly brackets and spaces) sorry, won't let me post a "real" link because I'm new.
m1990 is offline   Reply With Quote
Old 04-03-2012, 03:41 AM   #6
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,331
Default

ActionScript Code:
if(bar1.currentFrame < bar1.totalFrames) {     bar1.nextFrame(); }
[afz]snickelfitz is offline   Reply With Quote
Old 04-03-2012, 07:31 AM   #7
SolomonM
Registered User
 
Join Date: Mar 2012
Posts: 9
Default

Thanks alot, I used else ifs and it worked. Otherwise it would just go automatically to frame 6. Now it advances one frame every time the function is called.
SolomonM is offline   Reply With Quote
Old 04-03-2012, 07:32 AM   #8
SolomonM
Registered User
 
Join Date: Mar 2012
Posts: 9
Default

Quote:
Originally Posted by m1990 View Post
I am no expert by any means, and this is just a guess. However, I am currently in a flash class at my college and if I'm recalling correctly, a classmate made a comment regarding using multiple "if"s in the same way. I believe my professor said you would need to use "else if"s instead of continually using "if". Not sure if that is right or makes sense but it's worth a shot. Hope it works. If not, I tried =) Maybe the link below would help?

Thanks alot, I used else ifs and it worked. Otherwise it would just go automatically to frame 6. Now it advances one frame every time the function is called.
SolomonM is offline   Reply With Quote
Old 04-03-2012, 07:35 AM   #9
SolomonM
Registered User
 
Join Date: Mar 2012
Posts: 9
Default

Quote:
Originally Posted by iamgotenks View Post
does it just not work? or does it just go to frame 6?
It would just go to frame 6, but I changed the ifs to else ifs and it fixed it. Now it advances one frame every time the function is called.
SolomonM is offline   Reply With Quote
Old 04-03-2012, 07:37 AM   #10
bitbitbit
Member
 
Join Date: Aug 2008
Posts: 59
Default

The reason that the first code doesn't work is because after the first if the current frame changes to 2, this is after the first if and the program has not been in the other if's yet. So the program will check the second if next. Here the current frame changes to 3. This goes on and you will always end up with the last frame.
bitbitbit is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:41 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.