Skip to main content
Participant
July 22, 2006
Answered

scope problem within class with onPress

Hi there.. I have a class in which there are properties (IE - _myColor).

Now suppose withing my class I have an onPress function defined...

IE

targetMc.myBtn.onPress = function():Void {
trace("The current value is: " + _myColor);
}

Now obviously this will not work because it is out of scope.

What is the proper way to access said property from the onPress that resides IN the class file as well?

Thanks!
This topic is closed to new replies. Start a new post to keep the conversation going.
Peter LorentCorrect answer
Inspiring
July 23, 2006
You can use a local reference to the current object or use the Delegate Class. See attached examples.

4 replies

Inspiring
July 23, 2006
Dustin, you're welcome. Good luck with coding.
Translate
Peter LorentCorrect answer
Inspiring
July 23, 2006
You can use a local reference to the current object or use the Delegate Class. See attached examples.

Translate
d:n:kAuthor
Participant
July 23, 2006
That worked beautifully! I had been searching for some time yesterday and hte other offered results never worked for me. I did not use the delegate in this case (due to some other existing code), but will try the delegate after.

Thanks so much!
Translate
Inspiring
July 23, 2006
It’s your event handler that is making things undesirable. In the link below, LuigiL resolves this problem in an ‘onLoad’ event handler. If that doesn’t work then goto the link I posted in this thread.

http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=288&threadid=1144407&highlight_key=y&keyword1=LuigiL%20
Translate