A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] Quicker way to write these button actions

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    9

    [F8] Quicker way to write these button actions

    Hi there,

    I have 30 buttons, that i need to code all the same, except for changing the number.

    I'm sure you can do this by using arrays or something.

    so my array would look like:

    PHP Code:
    var buttons "1","2","3"...."29","30"
    And the buttons i'm trying to create would look like:

    PHP Code:
    button1.onRelease = function (){
            
    button1.gotoAndStop("selected");
    }
    button2.onRelease = function (){
            
    button2.gotoAndStop("selected");
    }
    button3.onRelease = function (){
            
    button3.gotoAndStop("selected");

    But i want to achieve this in 2 lines, something like this

    PHP Code:
    ['button' + [buttonVariable]].onRelease = function(){
           [
    'button' + [buttonVariable]].gotoAndStop("selected");

    Can anyone help?

  2. #2
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    How can you associate a gotoAndStop action to button... I suppose these would be movie clips... Can you please verfiy and clarify to us...

    As ever,
    Vinayak

  3. #3
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi all,

    Except of the issue noted by vinayak.kadam, a general code to achieve this would be for example:
    PHP Code:
    for (i=1;i<=30;i++){
        
    //Assume all buttons are in the  _root (main stage) otherwise you have to provide
        // the correct target path eg. _root.Container["button"+i] (if they are inside a "Container" clip for example)
        
    var myButton=_root["button"+i

        
    myButton.onRelease=function(){
            
    trace(this)
            
    this.gotoAndStop("selected"); 
            
    // Your rest actions here..
        
    }

    Best!

    Kostas
    Last edited by Kostas Zotos; 05-14-2008 at 01:58 PM.
    K. Zotos online portfolio: http://www.in3d.eu

  4. #4
    Junior Member
    Join Date
    May 2008
    Posts
    9
    yes, that's exactly it.

    Sorry, yeah i'm using movie clips, not buttons. (my bad).

  5. #5
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    Thats ok! It happens.... anyways Kostas has mentioned the correct method above to achieve this....

    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