PDA

View Full Version : Class member passing onPress problem



Cruiser
February 20th, 2004, 04:49 AM
Hi board,

I have a class which controls a movie clip. The movie clip has a button in it. The problem is that I cannot use the class members in the onPress function of the button.


class Controller {
private var id:Number; // I have tried public also
private var myClip:MovieClip; // The clip that has the button

public function Controller() {
// I have got the reference to the MovieClip that contains the
// button.

myClip.myButton.onPress = doSomething;
}

public function doSomething() {
trace(this.id); // <--- does not work. I tried without *this*
// the function is being called so thats not a problem
// Only the *id* is not accessible.
}
}


Thanks a lot.

Cruiser.

Cruiser
February 23rd, 2004, 12:59 AM
Anyone?

Voetsjoeba
February 23rd, 2004, 02:43 AM
In AS 2.0 classes, the this prefix is no longer necessary as it was in AS 1.0. So try this:



class Controller {
private var id:Number;
private var myClip:MovieClip;
function Controller(){
myClip.button.onPress = doSomething;
}
function doSomething():Void{
trace(id);
}
}