1 Reply Latest reply on Oct 12, 2009 5:02 AM by Ned Murphy

    addressing different parts of sprite in function?

    shintashi Level 1

      So I've got this function to make a sprite walk:

       

      function wlk(){
      if(Key.isDown(Key.RIGHT)|| Key.isDown(Key.LEFT) || Key.isDown(Key.UP) || Key.isDown(Key.DOWN)){
      walk++; if(walk > 2){walk = 0;}   
      chibi.tunicpants1.rtleg._y = 4 + walk;
      chibi.tunicpants1.ltleg._y = 5 - walk;
                  }
         
      }

       

       

      Which in the onEnterFrame looks like this:

       

      wlk();

       

       

       

      But what do I have to do to get the function to adress various versions, such as

      chibi.bluejeans1.rtleg._y = 4 + walk;
      chibi.bluejeans1.ltleg._y = 5 - walk;

       

      so that I can address each type for walking accordingly, through something like

      wlk(tunicpants1);

      wlk(bluejeans1);

      wlk(tuxedopants1);

       

      and so on?

       

      I tried something like this:

       

       

      //----------

      function wlk(s:String){
      if(Key.isDown(Key.RIGHT)|| Key.isDown(Key.LEFT) || Key.isDown(Key.UP) || Key.isDown(Key.DOWN)){
      walk++; if(walk > 2){walk = 0;}   
      chibi.tunicpant[s].rtleg._y = 4 + walk;
      chibi.tunicpant[s].ltleg._y = 5 - walk;
                  }
         
      }

       

      onEnterFrame = function(){

      wlk(s1);
      wlk(sA1);

      ...

      //-------------

       

      but it didn't work.

        • 1. Re: addressing different parts of sprite in function?
          Ned Murphy Adobe Community Professional & MVP

          Based on what I see in what you had, thhe following is what you probably want to do...

           

          onEnterFrame = function(){

               wlk("tunicpants1");  // use quotes

               wlk("bluejeans1");

               wlk("tuxedopants1");

           

          and so on

           

           

           

          function wlk(s:String){
               if(Key.isDown(Key.RIGHT)|| Key.isDown(Key.LEFT) || Key.isDown(Key.UP) || Key.isDown(Key.DOWN)){
                    walk++;

                    if(walk > 2){walk = 0;}   
                    chibi[s].rtleg._y = 4 + walk;
                    chibi[s].ltleg._y = 5 - walk;
               }

          }