4 Replies Latest reply on Oct 2, 2008 4:58 PM by Rothrock

    syntax question

    velocity-vector
      hello --

      i'm wondering if their is a way to compress this code for more efficiency. stepping up to AS3 soon!

        • 1. Re: syntax question
          Rothrock Level 5
          I probably wouldn't do it as a function, but rather...well there are probably a lot of things I would do differently there. But here is most likely what I would do.

          for(var i=1;i<=6;i++){
          var curItem:MovieClip=this["rack"+i]
          curItem.onRollOver=rackOver;
          curItem.onRollOut=rackOut;
          curItem.attachMovie("spreadOver","spreadOver",10,{_x:(i-1)*34,_y:-2,_height:2,_width:30,_v isible:false});
          curItem.ID=i;
          }

          function rackOver(){
          this.spreadOver._visible=true;
          }
          function rackOut(){
          this.spreadOver._visible=false;
          }

          Also if you do need to have the multiple if type of stuff, then I would use a switch statement:

          switch (item){
          case "rack1":
          // do something;
          break;
          case "rack2:
          // do something else;
          break;
          // and so on.
          }
          • 2. Re: syntax question
            velocity-vector Level 1
            cool. thanks so much! as always, more than one way to skin a cat.
            • 3. Re: syntax question
              velocity-vector Level 1
              are there any performance issues when you attach and remove an mc versus attaching an mc, hiding it then showing it after the event?

              thanks > mark
              • 4. Re: syntax question
                Rothrock Level 5
                You know I don't know. If there are children clips inside of an attached movie their properties, events, etc won't be available until one frame has advanced.

                Also in your example there would be a lot of code that needed to execute each time it was attached to place it. So I thought that was a bit "messy" and complex. I imagine there is a little memory overhead for having all six attached all the time. If these are little buttons or some such it probably isn't important. If these are giant 800 x 600 bitmaps that might be an issue. So ir really depends upon what you are doing!

                Generally I don't like to attach and remove a lot of clips. But it all depends upon what is in your clips and what you are trying to do.