Access a prefab propertes or method[SOLVED]

Hi I’ve a scene with this code

cc.Class({
extends: cc.Component,

properties: {
    btnStarGameNode: {
        default: null,
        type: cc.Node
    },
    btnSettingsNode: {
        default: null,
        type: cc.Node
    },
    buttonAudio: {
        default: null,
        url: cc.AudioClip
    },
    backgroundMusic: {
        default: null,
        url: cc.AudioClip
    },
    playerPrefab: {
        default: null,
        type: cc.Prefab
    }
},
// use this for initialization
onLoad: function () {
    var scene = cc.director.getScene();
    cc.audioEngine.playMusic(this.backgroundMusic, true);
    cc.audioEngine.setMusicVolume(0.2);
    var player = cc.instantiate(this.playerPrefab);
    player.parent = scene;
    player.setPosition(cc.p(0, 0));
    player.zIndex = 10;
    player.getComponent()
    player.playIdle();

}

This is the prefab script

cc.Class({
extends: cc.Component,

properties: {
   // main character's jump height
    jumpHeight: 200,
    // main character's jump duration
    jumpDuration: 0,
    // maximal movement speed
    maxMoveSpeed: 0,
    // acceleration
    accel: 0,
    
    animation: {
        default:[],
        type: cc.Animation
        
    }
    
},

// use this for initialization
onLoad: function () {
    

},

playIdle: function() {
    
    var anim = this.animation;
    anim.play('idle');
    
}

// called every frame, uncomment this function to activate update callback
// update: function (dt) {

// },

});

How can I access to prefab properties from scene. I try player.jumpHeight and player.getComponent(‘jumpHeight’). I try access a method playIdle from gamescene player.playIdle(); but return an error “playIdle is not a function”

The documentation is messed up regarding this, the “Access node and other component” section has the “Create and destroy node” explanation in it.

You can call playIdle function by using getComponent like in the following example:
(the parameter provided to getComponent here, is the prefab script name - I’ll suppose it is named player_script.js)

var player = cc.instantiate(this.playerPrefab);
player.getComponent('player_script').playIdle();

I’m doing this to call methods of a prefab and it works fine.
I did not tried to access properties like that, but I guess it should also work.
If not, just call a method that will initialise the properties you want.


Daniel

Thanks for your Help

onLoad: function () {
var scene = cc.director.getScene();
cc.audioEngine.playMusic(this.backgroundMusic, true);
cc.audioEngine.setMusicVolume(0.2);

    var player = cc.instantiate(this.playerPrefab);
    var anim = player.getComponent(cc.Animation);
    anim.play('idle');
    
    player.parent = scene;
    player.setPosition(cc.p(0, 0));
    player.zIndex = 10;
    var properties = player.getComponent('ninja');