vendredi 24 mars 2017

Getting child targets for mouse click event in OpenFL

I have a stage with multiple child object of different types. I have an event listener on the stage. I'd like to get the target child object on a mouse click so I can handle clicks on different object types.

Something along the lines of:

stage.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:Event):Void
    var target =
    // if target type is Foo
    //     target.aFooMethod();
    // else if target type is Bar
    //     target.aBarMethod();


Whats the correct way of doing this? Tracing seems to print the correct object type but I am unable to call any of the objects methods.

I vaguely remember in actionscript 3 being able to use but return null in this case.

Many thanks.

Thanks fot any help.

Aucun commentaire:

Enregistrer un commentaire