Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-03-2010, 04:16 AM   #1
Registered User
Join Date: Dec 2010
Posts: 17
Default If/Else statement using incrementing counter

Hey there,

I am trying to have it so depending on what number of times the button has been pressed determines which transition to do. Can someone help fix my code for this to be possible.

code is:
ActionScript Code:
public function next1(event:MouseEvent):void                     {                         var counter:int = new int();                         counter = 0;                         if(counter == 1)                         {                             var nxt2_btn:Tween = new Tween(nxt1_btn, "x", Back.easeIn, 459.3, 940.3, 1, true);                             nxt2_btn.addEventListener(TweenEvent.MOTION_FINISH, tranNextFrame);                             trace(counter);                         }                         else                         {                         var nxt1_btn:Tween = new Tween(nxt1_btn, "x", Back.easeIn, 459.3, 940.3, 1, true);                                    gradChannel.stop();                         nxt1_btn.addEventListener(TweenEvent.MOTION_FINISH, tranNextFrame);                         counter = counter + 1;                         }

Right now both transitions are the same, I know that but I am just trying to get the incrementing to work first.
afogo is offline   Reply With Quote
Old 12-03-2010, 06:19 AM   #2
Senior Member
Kritjon's Avatar
Join Date: Oct 2009
Location: Beijing, China
Posts: 244

ActionScript Code:
var counter:int = 0; function next1(event:MouseEvent):void {     counter = counter + 1;     if (counter == 1) {         var nxt2_btn:Tween = new Tween(nxt1_btn,"x",Back.easeIn,459.3,940.3,1,true);         nxt2_btn.addEventListener(TweenEvent.MOTION_FINISH, tranNextFrame);         trace(counter);     } else if (counter == 2) {         var nxt1_btn:Tween = new Tween(nxt1_btn,"x",Back.easeIn,459.3,940.3,1,true);         gradChannel.stop();         nxt1_btn.addEventListener(TweenEvent.MOTION_FINISH, tranNextFrame);     } }

If you work in a class, make sure you declare the variable 'counter' outside the function and inside the class.
Kritjon is offline   Reply With Quote
Old 12-03-2010, 08:13 AM   #3
Registered User
Join Date: Dec 2010
Posts: 17

Thank you. I realized what was wrong just a little bit after posting this.
afogo is offline   Reply With Quote

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 04:21 PM.

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.