4 Replies Latest reply on Mar 15, 2007 7:29 AM by LiChaoping

    same trace,two results,why?

    LiChaoping
      //.....................
      trace(channelbtn[channellistnum+channelshownum]);//line1
      programtween_y.onMotionStopped = function(){
      trace(channelbtn[channellistnum+channelshownum]);//line2
      }
      //....................
      //line1,trace right result,but line2 trace undefined,why???
      "channelbtn[channellistnum+channelshownum]" is a button object, "channellistnum" and "channelshownum" are two numbers,they've been defined above line1,so line1 trace right result,but why line2 trace undefined?what's the different between these two function ways below:
      1. function a(){}
      2. a = function(){}

      Thank you for reply.......
        • 1. Re: same trace,two results,why?
          ggshow Level 2
          // when you trace something here, it mean "something"
          programtween_y.onMotionStopped = function(){
          // when you trace something here, it mean programtween_y.something
          }
          • 2. same trace,two results,why?
            LiChaoping Level 1
            quote:

            Originally posted by: ggshow
            // when you trace something here, it mean "something"
            programtween_y.onMotionStopped = function(){
            // when you trace something here, it mean programtween_y.something
            }


            Thank you , ggshow, then can i change it like this:
            _parent.trace(something);

            is this equal trace in line1??
            I've tried it ,it's still not work.
            • 3. Re: same trace,two results,why?
              Level 1
              Nope it would be:
              programtween_y.onMotionStopped = function(){
              trace(_parent.channelbtn[_parent.channellistnum+_parent.channelshownum]);//line2
              }

              Although there are more elegant ways of doing this.
              • 4. Re: same trace,two results,why?
                LiChaoping Level 1
                thank Osh_it,now i know where the problem is:
                In AS2.0,function like this way need Delegate!!!!This is very important,because the object is undefined in this function way.
                //----------------
                programtween_y.onMotionStopped = function(){
                trace(channelbtn[channellistnum+channelshownum]);//line2
                }
                //----------------
                so,we should use this function like this:
                //----------------
                programtween_y.onMotionStopped = Delegate.create(this,aaa);
                private function aaa(){
                trace(channelbtn[channellistnum+channelshownum]);//line2
                }
                //----------------
                It's ok,now!!!