I’m creating MyButton class using the MovieClip class. The problem is getting onRollOver to reDraw MyButton. The scope appears to be wrong, please help. This is a simplified version to represent the problem.
// Menu.fla
//Create an Instance of MyButton
var b:MyButton = new MyButton();
//MyButton.as Class
class MyButton{
private var mc:MovieClip;
public var xPosition:Number;
public var yPosition:Number;
public var width:Number;
public var height:Number;
public var fill;
//Construct MyButton
public function MyButton(){
create();
drawRect(0, 0, 100, 22, 0xccddaa);
drawOver();
}
//Create MovieClip Instance
private function create():Void {
mc = _root.createEmptyMovieClip(“buttonx”, 0);
}
//draw MyButton Shape
private function drawRect(xPosition, yPosition, width, height, fill) {
var ax = xPosition+width;
var ay = yPosition;
var bx = xPosition;
var by = yPosition+height;
mc.clear();
mc.beginFill(fill, 90);
mc.lineStyle(1, 0xccddee);
mc.moveTo(xPosition, yPosition);
mc.lineTo(ax, ay);
mc.lineStyle(1, 0xccddee);
mc.lineTo(ax, by);
mc.lineStyle(1, 0xccddee);
mc.lineTo(bx, by);
mc.lineStyle(1, 0xccddee);
mc.lineTo(bx, ay);
mc.endFill();
}
//reDraw MyButton onRollOver
private function drawOver(){
mc.onRollOver = function(){
drawRect(0, 0, 100, 22, 0x000000);
}
}
}