How do I play an audiosource without specifying the name?

I am trying to call the function, but instead of passing the play function a specific name string, I want to just play whatever audiosource is attached to the entity (you can assume there is just one). I thought maybe the assets array might work so I tried something like this:[0].getName());

The code below works fine, because I just specify the name string for the audiosource directly. But I don’t want to do that. Because I want to use the same script for multiple entities. So that when I click on an entity, it plays the associated audiosource. I know you can have multiple audiosources for an entity, so I just want to be able to play the first audiosource in the list. Any help?

pc.script.create('clickme', function (app) {
    // Creates a new Clickme instance
    var Clickme = function (entity) {
        this.entity = entity;

    Clickme.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function () {
            app.mouse.on(pc.EVENT_MOUSEDOWN, this.onSelect, this);

        onSelect: function (e) {
            this.cam1 = app.root.findByName("Camera1");
            var from =, e.y,;
            var to =, e.y,;

  , to, function (result) {
                var pickedEntity = result.entity;
        // Called every frame, dt is time in seconds since last update
        update: function (dt) {

    return Clickme;

You could use the following; the reason that your version didn’t work is because the assets array on the component references the asset’s id, not the actual asset. Therefore you need to find the actual asset using app.assets.get.[0]).name);