Vikana
12-09-2005, 02:36 PM
Hi
I wonder if you can help. I want to create a custom method for a mouse event handler attached to a movie clip on the stage,
Please look at sample code
ActionScript Code:
/** test class to show what I need to get custom
* mouse methods working
*/
class MouseListener {
// holder for the mouse object
private var mouse_mc:MovieClip;
// constructor
public function MouseListener(target:MovieClip, depth:Number){
mouse_mc = target.createEmptyMovieClip("mouse" + depth, depth);
drawGraphic();
createMouse();
}
// creates the event handler
public function createMouse():Void{
mouse_mc.onRelease = function(){
test1();
}
}
// custom method I want to run
public function test1():Void{
trace("test2");
}
// creates the image
public function drawGraphic():Void{
// clears the image first
mouse_mc.clear();
// use a 1-point line for outline
mouse_mc.lineStyle(1, 0xBAD9EF);
mouse_mc.moveTo(0,0);
// start fill
mouse_mc.beginFill(0xBAD9EF, 100);
// draw the border of the box
mouse_mc.lineTo(50, 0);
mouse_mc.lineTo(50,50);
mouse_mc.lineTo(0, 50);
mouse_mc.lineTo(0,0);
// end the fill
mouse_mc.endFill();
}
}
test1 method will not run, could anybody please give me some pointers on what I am doing wrong.
Thanks
Vikana
I wonder if you can help. I want to create a custom method for a mouse event handler attached to a movie clip on the stage,
Please look at sample code
ActionScript Code:
/** test class to show what I need to get custom
* mouse methods working
*/
class MouseListener {
// holder for the mouse object
private var mouse_mc:MovieClip;
// constructor
public function MouseListener(target:MovieClip, depth:Number){
mouse_mc = target.createEmptyMovieClip("mouse" + depth, depth);
drawGraphic();
createMouse();
}
// creates the event handler
public function createMouse():Void{
mouse_mc.onRelease = function(){
test1();
}
}
// custom method I want to run
public function test1():Void{
trace("test2");
}
// creates the image
public function drawGraphic():Void{
// clears the image first
mouse_mc.clear();
// use a 1-point line for outline
mouse_mc.lineStyle(1, 0xBAD9EF);
mouse_mc.moveTo(0,0);
// start fill
mouse_mc.beginFill(0xBAD9EF, 100);
// draw the border of the box
mouse_mc.lineTo(50, 0);
mouse_mc.lineTo(50,50);
mouse_mc.lineTo(0, 50);
mouse_mc.lineTo(0,0);
// end the fill
mouse_mc.endFill();
}
}
test1 method will not run, could anybody please give me some pointers on what I am doing wrong.
Thanks
Vikana