- Home /
Application.ExternalEval - variable for links to reuse for multiple objects
hi,
I would to reuse this script
function OnMouseDown():void {
Application.ExternalEval("window.open('http://www.google.com')");
}
for multiple objects with different links ... I'm trying to pass the web link from the variable but it doesn't work!
var setURL = '';
function OnMouseDown():void {
Application.ExternalEval("window.open(setURL)");
}
suggestions? thanks!
Answer by Bunny83 · Mar 12, 2012 at 01:51 PM
Don't mix up different contexts. Unity's scripting environmant is completely seperated from the website the player runs in. You can't use a variable defined in Unity in webpage javascript, but you can pass the content of that variable like this:
var setURL = '';
function OnMouseDown():void { Application.ExternalEval("window.open('" + setURL + "')"); }
still doesn't work...
var setURL : String = "http://www.google.it";
function On$$anonymous$$ouseDown():void {
Application.ExternalEval("window.open(" + setURL + ")");
}
Well, it looks to me like you're missing some quotes:
Application.ExternalEval("window.open('" + setURL + "')");
Doh! :D $$anonymous$$y bad... forgot it's a string. I will fix it (but it may take a while until it's visible...)
Answer by lcn75 · Mar 12, 2012 at 04:42 PM
here the solution:
var setURL : String = "http://www.google.it";
function OnMouseDown():void {
Application.ExternalEval("window.open('" + setURL + "')");
}
thank you all!