# Gigantic brain needed... AS3 class quandry

**URL:** <https://forum.kirupa.com/t/gigantic-brain-needed-as3-class-quandry/283083>\
**Category:** flash\
**Created:** [March 2, 2009, 3:13pm UTC](https://forum.kirupa.com/t/gigantic-brain-needed-as3-class-quandry/283083 "2009-03-02T15:13:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![letter](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@letter](https://forum.kirupa.com/u/letter)\
**Post date:** [March 2, 2009, 3:13pm UTC](https://forum.kirupa.com/t/gigantic-brain-needed-as3-class-quandry/283083/1 "2009-03-02T15:13:07Z")

</div>

I’m having a challenge getting an event listener to use the target of the click to trigger a method of a custom class… probably easier to show in this super stripped down version. Here’s the class:

```auto
 
package {
 import flash.display.*;
 public class MyClass extends MovieClip {
  public var newObject:MovieClip;
  
  public function MyClass(whichClass:Class, whereToAdd:Object):void {
    newObject = new whichClass();
    whereToAdd.addChild(newObject);
    newObject.x=200;
    newObject.y=200;
  }
  public function hello():void {
   trace("HELLO WORLD");
  }
 }
}
 

```

and here’s the fla (which has one movie clip in the library… a simple box with a class of “square”):

```auto
 
var mySquare:square = new square();
var myObject:MyClass = new MyClass(square, this);
myObject.hello(); // this traces "HELLO WORLD"
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseHandler);
function mouseHandler(evt:Event):void {
 trace("clicked");
 evt.target.hello(); // this throws an error: "hello is not a function" instead of tracing "HELLO WORLD"
}

```

Any brains out there that can give some input?
