Skip to main content
Participant
March 14, 2007
Question

same trace,two results,why?

  • March 14, 2007
  • 3 replies
  • 322 views
//.....................
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.......
This topic has been closed for replies.

3 replies

Participant
March 15, 2007
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!!!
March 14, 2007
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.
Participating Frequently
March 14, 2007
// when you trace something here, it mean "something"
programtween_y.onMotionStopped = function(){
// when you trace something here, it mean programtween_y.something
}
Participant
March 14, 2007
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.