Hi @Rob,
I’m a bit lost here :) I’m trying to make the example on the communication doc to work first but I fail to do that, too.
Here is how I call C# code from Lua:
local requestingMessageBoxEvent = { name = "requestingMessageBox", message = "Hello World!" } local result = Runtime:dispatchEvent( requestingMessageBoxEvent ) -- Print the message returned by C# print( "result is", tostring(result) ) --always returns FALSE
As I understand, I have to insert C# code into the MainPage.xaml.cs, right? Here is my MainPage.xaml.cs:
* When I try Console.WriteLine(), it doesn’t seem to print anything to the console (when debugging on device) so I’m not pretty sure that I have access to these methods.
private void OnCoronaRuntimeLoaded(object sender, CoronaLabs.Corona.WinRT.CoronaRuntimeEventArgs e) { e.CoronaRuntimeEnvironment.AddEventListener("requestingMessageBox", OnRequestingMessageBox); //e.CoronaRuntimeEnvironment.AddEventListener("requestingMessageBox", OnPlayVideo); } private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnRequestingMessageBox( CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e) { var boxedMessage = e.Properties.Get("message") as CoronaLabs.Corona.WinRT.CoronaBoxedString; if (boxedMessage == null) { return CoronaLabs.Corona.WinRT.CoronaBoxedString.From("'event.message' is a required field."); } return CoronaLabs.Corona.WinRT.CoronaBoxedString.From("Message box was displayed successfully!"); } private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnPlayVideo( CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e) { try { // Create a path to a video file. // This example assumes a video file named "MyVideo.m4v" is in your Resource directory. var uri = new Uri( "ms-appx:///Assets/Corona/videos/Giris.mp4", UriKind.RelativeOrAbsolute); // Play the video. // Note: It's your responsibility to create and store the MediaElement object. // Because you'll need to add the ability to remove it later, outside of this method. mediaElement.Source = uri; mediaElement.Play(); } catch (Exception) { // Failed to load the video file! } return CoronaLabs.Corona.WinRT.CoronaBoxedString.From("Message box was displayed successfully!"); }