Cc system event editor bug?

Hi dear community,
I created one event but when i just put cc.systemEvent.on(‘somEventName’, this.someFunction, this) it generates an error in the editor console.
When i execute the code it works perfectly.

image

The error seems to say like cc.systemEvent is undefined.

Sorry, this looks like a bug in the editor. Your code looks correct, and if it executes than it’s purely in the editor. Which version of CC are you using?

@skara really thank you for you reply
Latest stable version. Cocos creator 2.1

I can’t reproduce this issue on creator 2.1 version.
Code:

    onLoad () {
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
        cc.systemEvent.on("somEventName", this.somEvent, this);
    },

    start () {
        
    },

    somEvent (event) {
        cc.log("emit some Event");
    },

    onKeyDown (event) {
        cc.log(event.keyCode);
        cc.systemEvent.emit("somEventName");
    },

Did you used customized engine?

@Big_Bear really thank you.
No, it’s really peculiar because i have done this in other parts of the project. I can give u some code but i need to get the office. About 2 hours you have the code for sure.

Gives error


don’t gives error

Could be because extends from cc.Label? cc.Label extends cc.Component so shouldn’t be this

I got the error,it cause by extends from cc.Label.I need some time to check it,feedback later

To seeing if together we can find a way of solving it. Really thank you, @Big_Bear.

@Big_Bear, @jare
As I see, If u extends any cc.component. onload() and start() fucntions are called even in the editor. Is that normal?
So, for example:
if i want to add some spriteframes to toggle the sprite when some entity is clicked. My way would be extend cc.sprite create 2 cc.SpriteFrame and then change the cc.Sprite.spriteFrame property to one of this spites frames.

the bug cause by the cc.system is not init in the editor when you extends to engine component(like cc.Label,cc.Sprite).
we fixed it and it will update in version 2.0.7

thank you for ur reply @Big_Bear.
I’m currently working at 2.1, this bug can still fixed in 2.1.1?

next version will be 2.0.7
it will fix some bug of 2.0.x version.and the 2.1.1 will be a bit later

1 Like