dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: different actions each time same button is pressed?

  1. #1
    Member
    Join Date
    Mar 2003
    Posts
    50

    different actions each time same button is pressed?

    Hi,

    First, I am using CS3 and AS2.0

    Not exactly sure how to do this. I have a button that I would like to do the following:

    1st time it is pressed it goes to a specific frame in the timeline
    2nd time it is pressed it goes to a DIFFERENT frame in the timeline
    3rd time it goes to another frame
    4th time to another
    5th time it goes back to frame 1 in the timeline

    The frames can be consecutive (i.e. frames 1 - 5)

    I know how to make a button goto a specific frame in a timeline, but I don't know how to script it so that the same button pressed multiple times will go to a different frame after each click.

    I have no idea if this is simple or complicated to setup, but if anyone can point me in the right direction of a tutorial (can't seem to find one for this) or could give me some tips on how to write the code out it would be great.

    Thanks...

  2. #2
    Maybe not ideal, but it works.

    Code:
    var counter:Number = 0;
    
    button.onRelease = function(){
    if (counter==0) {
    // Do something
    } else if (counter==1) {
    // Do something
    } else if (counter==2) {
    // Do something
    } else if (counter==3) {
    // Do something
    } else if (counter==4) {
    // Do something
    }
    
    // Reset counter
    if (counter==5) {
    counter=0
    } else {
    counter++
    }

  3. #3
    Member
    Join Date
    Mar 2003
    Posts
    50
    Thanks. This gives me a place to start. Here's the code that I have now for my button (updateBTN = instance name)

    Code:
    var counter:Number =0;
    updateBTN.onRelease=function(){
           if (counter==0) {
               gotoAndStop(1);
               }
               else if (counter==1) {
                    gotoAndStop(2);
               }
               else if (counter==2) {
                    gotoAndStop(3);
               }
               else if (counter==3) {
                    gotoAndStop(4);
               }
               else if (counter==5) {
                          counter=0
               } else {
                     counter++
               }
    }
    I'm getting a couple of errors on this code though.

    1) var counter:Number=0;
    (ERROR Message: statement must appear within on handler??)
    2) updateBTN.onRelease=function()}
    (ERROR Message: statement must appear within on handler??)

    EDIT: Nevermind. I had the code on my button and not on a frame in the timeline. It's working now.
    Last edited by popflier; 08-27-2008 at 04:11 PM.

  4. #4
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    Quote Originally Posted by funkage
    Maybe not ideal, but it works.
    Finishing the job in right time is very important then to waste time justifying what is ideal and what isi'nt..... u have done a good job..... for a newbie its very good solution.....
    As ever,
    Vinayak Kadam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center