I meant that you could do something like this, where the reference to the class object is passed to the button so that the function in the class object scope can be called from within the button scope.
It's easier to explain in code...
Code:class MyMenu extends MovieClip { // declare the button specific vars so you don't get compile errors. var scope:MovieClip, id:Number; // constructor function MyMenu() { var _mc:MovieClip; for(var i:Number=0; i<5; i++) { // create the clips and assign the mouse event _mc = createEmptyMovieClip('_btn'+i, i); _mc.onRelease = buttonRelease; // vars to be passed as argument to the someClassFunc _mc.id = i; // a reference to the class object so that the someClassFunc can be correctly addressed and executed _mc.scope = this; // draw and position the buttons _mc.beginFill(0xFF, 100); _mc.lineTo(50,0); _mc.lineTo(50,50); _mc.lineTo(0,50); _mc.lineTo(0,0); _mc.endFill(); _mc._y = i*55; } } // function will run in the class object scope private function someClassFunc(id:Number, btn:MovieClip):Void { trace("Button id: "+id); trace("Button ref: "+btn); trace("Scope of this function: "+this); } // the onRelease function running in the individual button's scopes private function buttonRelease(Void):Void { this.scope.someClassFunc(this.id, this); } }




...
Reply With Quote