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!

2 Answers

2

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 + "')");
}

Well, it looks to me like you're missing some quotes: Application.ExternalEval("window.open('" + setURL + "')");

Doh! :D My bad... forgot it's a string. I will fix it (but it may take a while until it's visible...)

here the solution:

var setURL : String = "http://www.google.it";

function OnMouseDown():void {
    Application.ExternalEval("window.open('" + setURL + "')");
}

thank you all!