Go Back   kirupaForum > Flash > ActionScript 1.0/2.0

Reply
 
Thread Tools Display Modes
Old 11-26-2009, 06:32 PM   #1
Tuesday
Registered User
Pallete How to check for sequential clicks?

What I want to do is have a menu where the user navigates by clicking buttons in a sequential order. For example, if the user clicks button 1, then 2, then 3, they are taken to page 1. If they click button 2, then 3, then 1 they are taken to page 3, etc.

I'm really just not sure where to start or what terms i could use to search for info on this. I have tried many combinations with "sequence" and "sequential" with no luck so far.

I think I would use some combination of conditionals with states but I'm new enough to AS that I can't quite make sense of it or figure out how to find more info on doing something like this.
Tuesday is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-26-2009, 07:29 PM   #2
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
Let's say that you have your three buttons on the stage and have given them the instance names `btn1`, `btn2`, and `btn3`. First you should assign the same click handler to each button and this handler should record the order in which buttons are clicked. Once you have a set number of clicks recorded (i.e. 3) then you should process which buttons have been clicked and in which order then act appropriately.

You might do that with something very roughly like the following (I don't have flash installed to test it, you see), which ought to provide a basic implementation of what you're looking for:
ActionScript Code:
/*
 * These are the buttons that we wish to track the sequential
 * clicks of.
 */

var buttons:Array = [btn1, btn2, btn3];

/*
 * A text record of the buttons that have been clicked.
 */

var record:String = '';
/*
 * The number of button clicks we wish to record beforing
 * checking
 */

var recordLength:Number = 3;

/**
 * Handle the clicks of the button.
 *
 * Maintains the record and checks to see what action should
 * be performed if we have recorded enough.
 */

function clickhandler()
{
    // Add this button's id (explained later) onto the end of the record
    record = record + this.id;
   
    if (record.length == recordLength)
    {
        /*
         * Process which order the buttons were clicked in
         */

        if (record == '123')
        {
            // User clicked button 1, 2 and then 3.
        }
        else if (record == '321')
        {
            // User clicked button 3, 2 and then 1.
        }
        else
        {
            // User clicked the buttons in some other order.
        }
       
        // Reset the record
        record = '';
    }
}

/*
 * We want to do the following for each button
 */

for (var i = 0; i < buttons.length; i++)
{
    /*
     * The id property of each button will be used to form
     * the parts of the record of clicks that correspond to the
     * respective button being clicked.
     *
     * We're using Strings so that we can concatenate them easily.
     */

    buttons[i].id = (i + 1).toString();
   
    /*
     * Assign the click handler
     */

    buttons[i].onclick = clickhandler;
}


Hope that helps
icio is offline   Reply With Quote
Old 11-27-2009, 04:22 AM   #3
Tuesday
Registered User
Ah! You make it look so easy! I had to tweak it a little bit but it actually worked! Thank you so much!

!!!
Tuesday is offline   Reply With Quote
Old 11-27-2009, 07:45 AM   #4
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
You're welcome
icio is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 -4. The time now is 09:58 AM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com