How to add click listener for class Sprite

I create some sprite class (they are just pictures).I want to click them and then make them move.
how to achieve it???

Hi,

You need to add listen the touch event in its parent layer, and then when you handle the touch event, you can detect if it’s related to your sprite, so can do some manipulations. There is no direct event dispatching for sprites.

Huabin

but how to detect if it’s related to my sprite…….

Firstly, you can register the sprite object as a property in your layer class or add the sprite with a predefined tag.
Then when you handle your touch event, just retrieve the sprite with your property or sprite tag so that you can check the touch point position with the bounding box of your sprite.

That’s it.

hi……
This is my source code,when I click the layer the console will print “layer was clicked”.
I want to the sprite is clicked that the console will print something else……
I halfly know what you mean but I don’t know how to exactly code it……
Can you change my codes

thank you,that is always you to anser me every time I ask the questions……

*/

var GameLayer = cc.Layer.extend({
    ctor: function () {
        this._super();
        if ('mouse' in sys.capabilities )
            this.setMouseEnabled(true);
    },
    init: function () {
        //call super class's super function
        this._super();

        //add pop_sprite
        var pop_sprite=cc.Sprite.create(color[random_color]);
        pop_sprite.setPosition(200,200);
        this.addChild(pop_sprite);
    },
    onMouseUp:function(event){
        console.log("layer was clicked......");
    }
});

var GameScene = cc.Scene.extend({
    onEnter: function () {
        this._super();
        var layer = new GameLayer();
        layer.init();
        this.addChild(layer);
    }
});