Skip navigation
ilovetoread247
Currently Being Moderated

Help With Button Coding

Apr 5, 2012 8:13 AM

Tags: #button #as2 #actionscript #2.0

I make dress up games in ActionScript 2, and am having a problem.

 

I want to make a button find all movieclip items with, say, "shirt" in their Instance Name, and move them to frame 2.  I know how to do this with one item, (on(release){

_root.shirt1.gotoAndStop(1);

}

and on previous games, I merely copied and pasted that several dozen times for every item.  However, on this game, I am trying to cut down on code, and learned how to use

 

for(var i:String in _root){

     if(i.indexOf("_drag") > -1){

          _root[i].onPress = function(){

 

(put in the code)

(put in the closing }s)

 

on the stage to make items drag and snap into place.  I have learned that this code cannot be used on buttons, which need static commands, I think?  I'm still very much a novice.

 

Any help would be appreciated!

 
Replies
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 5, 2012 8:47 AM   in reply to ilovetoread247

    what is it that, you think, doesn't work with buttons?

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 5, 2012 5:33 PM   in reply to ilovetoread247

    you should remove all code from objects.  so, whatever button has that code attached should be given an instance name (eg, btn) so you can use:

     

    btn.onRelease = function(){

         for(var i:String in _root){

              if(i.indexOf("shirt") > -1){

                   _root[i].gotoAndStop(2);

                   }

              }

         };

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points