Help with calling conditions / expressions from domSide.js

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi, I am working on porting Rex's Youtube Player addon from C2 to C3.

    So I am able get the Youtube player playing, but I couldn't find out how to let the callback functions in domSide.js communicate with conditions.js or expressions.js. I am still relatively new to the addons coding scene, and by referencing the example addons available, I have only seen triggering of conditions / expressions from instance.js. Any help would be appreciated, Thanks!

    var self = this;
    var onPlayerStateChange = function (event)
    {
    	//if (event["data"] === self.youtube_state)
    	// return;
    		
    	self.youtube_state = event["data"];	 
    				
    	// do looping
    	if ((self.youtube_state === 0) && self.cur_isLooping)
    	{
    		self.youtube_player["playVideo"]();
    	} 
    
    	console.log("onPlayerStateChange: " + self.youtube_state);
    	// how to trigger C3.Plugins.YT_API.Cnds.OnPlaybackEvent ??
    };
    
    var onPlayerReady = function (event)
    {	 
    	// old code from C2 self.runtime._trigger(cr.plugins_.rex_youtube_player.prototype.cnds.OnPlayerReady);
    };
    
    var onPlayerError = function (event)
    {
    	self.exp_errorCode = event["data"];
    	// old code from C2 self.runtime._trigger(cr.plugins_.rex_youtube_player.prototype.cnds.OnPlayerError);
    };	 
    
    var playerVars = {};
    playerVars["autoplay"] = 1;
    this.youtube_player = new window["YT"]["Player"](
    	elemId, 
    	{ "videoId": videoId, 
    	"playerVars": playerVars, 
    	"events": {"onStateChange": onPlayerStateChange,
    				"onReady": onPlayerReady,
    				"onError": onPlayerError
    				}
    	}
    );
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • To support the runtime running in a Web Worker, you need to use message passing between the runtime and DOM contexts. The ISDKInstanceBase methods like _addDOMMessageHandler() and _postToDOM(), and the corresponding DOM-side methods, can help with that. The domMessagingPlugin addon sample has some sample code along those lines.

  • Thank you Ashley for reply~ I have finally got it to work by cloning the domElementPlugin sample and starting from there. I think the key is that when the DOM Element is created, it has the elementId needed to point back to the Instance by calling PostToRuntimeElement().

    Also by referencing another project file drag-drop-files, I got a clearer picture on variable passing with PostToRuntimeElement() and how to access the variable in Instance.js.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)