GSA_DC wrote:
I have a problem now in getting clicked markers sending messages (their name or identifier) back to Livecode! Any idea?
Kind regards, Paul.
i'm afraid you can't invoke lc from javascript.
but you can write a js function and invoke it from lc periodically (every 500 millisecs?) to get data back.
try this (just an idea):
/*LC card handlers*/
Code: Select all
local sBrowserId //your browser instance id
local sDataFromJs //a local to store data back from js, if needed
local sMessageID //a local to delete the sent message on closing card
constant kDelay = 500 //millisecs!
on letsStart
sendData "writeTracking", "myData"
send "checkData" to me in kDelay millisecs
put the result into sIDMessage
end letsStart
command checkData
put getData("readTracking()") into sDataFromJs
if sDataFromJs is not empty then
doMyStuff
end if
send "checkData" to me in kDelay millisecs //or not, if sDataFromJs <> empty and you're already happy
put the result into sIDMessage
end checkData
command sendData pFunction, pMsg
local tResult
//i.e. string pFunction = "writeTracking", a js function ; string pMsg = the data to send, ex.: "data1||data2||data3"
if sBrowserId is not an integer then exit sendData
if environment() = "mobile" then
//run js script to send data
mobileControlDo sBrowserId, "execute", pFunction & "('" & pMsg & "')"
put the result into tResult
else
get revBrowserExecuteScript(sBrowserId, pFunction & "('" & pMsg & "')")
//or
//get revBrowserCallScript(sBrowserId, pFunction, pMsg)
put it into tResult
end if
//eventualy check tResult for error code, if provided
end sendData
function getData pFunction
local tResult
//i.e. string pFunction = "readTracking()" , a js function returning data
if sBrowserId is not an integer then exit getData
if environment() = "mobile" then
//run js script to get data back
mobileControlDo sBrowserId, "execute", pFunction
put the result into tResult
else
//run js script to get data back
get revBrowserExecuteScript(sBrowserId, "result="& pFunction)
put it into tResult
end if
return tResult
end getData
on closeCard
if "checkData" is in the pendingmessages then delete sMessageID
end closeCard
/*JAVASCRIPT STUFF */
Code: Select all
function readTracking() {
//send data
var tracking = '<the data you stored somewhere waiting for the LC request>';
return tracking;
}
function writeTracking(tracking) {
//get data
var tracking = tracking.split('||');
track_data1 = tracking[0].split(',');
track_data2 = tracking[1].split(',');
track_data3 = tracking[2].split(',');
/*and so on…*/
/*do your stuff*/
return '<good|bad status code>';
}
better ideas are welcome, of course. as usual.
regards.