Shared Object Reference

Shared Object Reference
0.0 0


I am very new to Cocos2d-html5 and have almost forgotten how javascript works. What I want to do is create a shared instance of an object and to access it from various other classes. What i want to do is exactly how we access the CCDirector sharedInstance. I looked that code and this is what i did
var sharedInstance = null;
var GameScene = cc.Scene.extend({

onEnter:function () {
sharedInstance = new GameSceneLayer();


In my other .js file I access the sharedInstance directly. I can access it and get all the data associated with it, but the problem is that any sprite I load after that is not aligned properly. This is what Im doing in the other file


var size = (sharedInstace.profilesData.length + 1) / 3;
var start = screenNo * size;
var sprite = cc.Sprite.create(sharedInstance.profilsData[start]);

In the above case, profilesData is an array that holds the path to the sprite. The sprite loads correctly, but it is always displayed at (0,0)
even though i set the position to something else. Can anyone help me with this?


bump! anyone?


guys! really need help


As to your code , your behavior is right.
I just guess that your resources were not preload .
Can you packaged and upload your code?


Sorry for the delay in the reply, as the website was down. I have attached the .js files in the zip below. Please have a look. I cannot unfortunately share the images, so if u try to directly run these files, it will crash. Also, the first file to begin with is “GameScene.js” . Thanks.


I have tested your code.
I saw that sprite displayed correctly.
Please look over attachment.


U used a shared object reference? Any idea why its not working at my end? Thanks for the help though. :slight_smile: