I started developing an HTML5 game using the EaselJS library. When creating a class called Bot
, which will contain the code of the robot used in the game, I get the following error:
Uncaught TypeError: Cannot read property 'getContext' of undefined
AsfarasIunderstand,thiserroroccurswhenJavaScriptexecutesbeforethecanvashasbeeninitialized.Butthisdoesnotseemtobethecase(theinstanceofclassBot
iscreatedonlyinthehandleImageLoad
call,afterthespritesheetimageisloadedintotheinit
callmadeintheeventonLoad
ofthebodyoftheHTML).
Debugging,itseemstomethattheerroroccurswhentryingtocreatetheSpriteSheet
(withintheinitialize
call).Iputthe code in JSFiddle . Can anyone identify where I'm going wrong?