00:00
00:00
Newgrounds Background Image Theme

KiichigoInu just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

ExternalInterface .call "stuck"

749 Views | 13 Replies
New Topic Respond to this Topic

ExternalInterface .call "stuck" 2013-07-24 16:45:58


Hello there. I know the problem is already popular with tens of links on Google, but I tried almost every mentioned solution and nothing worked. I changed "Access playback security" to "Access network only". I insured the "allowScriptAccess" HTML value was either "always" or "sameDomain". I tried using javaScript functions instead. I insured the needed classes are imported. Nothing worked, at all. Running the file in Flash returned "null". In Chrome/Firefox, the above happened.

I decided to upload on NG instead of bothering with the HTML code, but the HTML page code I use locally is the default Adobe publisher. I edited the sameDomain value manually, though.

Here's the code of the MouseEvent function when you click the "box with the white background".

private function windowClicked(e:Event = null) {
	var resultS:String = "Test";

	if(ExternalInterface.available)
	{
		resultS = ExternalInterface.call("window.location.href.toString");
	}
	else
	{
		resultS = "External Interface unavailable";
	}

	if(resultS==null || resultS == "") resultS = "Nothing..";

	resultS = "Nothing";

	myText.htmlText = '<font color="#000000">' + "Clicked : " + N + ". Result: " + resultS + '</font>';
	N++;

	trace(resultS);
}

And here's the SWF. http://www.newgrounds.com/dump/item/09ec1dccb9bbb9d600a749ca 4b3ad0e6

The reason I know it's "stuck" is because this line,

myText.htmlText = '<font color="#000000">' + "Clicked : " + N + ". Result: " + resultS + '</font>';

never appears. And as I mentioned, it does in Flash, but on Chrome nor Firefox.

As always, any help is appreciated. Thanks.


Nav.. I'm the Nav!

Response to ExternalInterface .call "stuck" 2013-07-24 16:58:54


So great you told us about your solution that doesn'T work, but what is the actual question?
What do you want to achieve?

I assume you want to know the current url, which you can find in loaderInfo.url
no need for JS

Response to ExternalInterface .call "stuck" 2013-07-24 17:16:15


At 7/24/13 04:58 PM, milchreis wrote: So great you told us about your solution that doesn'T work, but what is the actual question?
What do you want to achieve?

I assume you want to know the current url, which you can find in loaderInfo.url
no need for JS

I need to fix the ExternalInterface.call function to be able to call JS functions. I really need to do so because I'm also implementing lights on/off modes, which has to be through calling JavaScript functions, so I don't only need to get the URL I need to access other functions as well.


Nav.. I'm the Nav!

Response to ExternalInterface .call "stuck" 2013-07-24 17:24:55


At 7/24/13 05:16 PM, TheNavigat wrote: I need to fix the ExternalInterface.call function to be able to call JS functions. I really need to do so because I'm also implementing lights on/off modes, which has to be through calling JavaScript functions, so I don't only need to get the URL I need to access other functions as well.

Then post those functions, where they are and how you call them.

Your debugging is not too reliable. There can be other reasons why the textfield does not display a text, say font embedding issues for example.
Instead, use a trace statement or throw an error.

Response to ExternalInterface .call "stuck" 2013-07-24 17:33:01


At 7/24/13 05:24 PM, milchreis wrote:
At 7/24/13 05:16 PM, TheNavigat wrote: I need to fix the ExternalInterface.call function to be able to call JS functions. I really need to do so because I'm also implementing lights on/off modes, which has to be through calling JavaScript functions, so I don't only need to get the URL I need to access other functions as well.
Then post those functions, where they are and how you call them.

Your debugging is not too reliable. There can be other reasons why the textfield does not display a text, say font embedding issues for example.
Instead, use a trace statement or throw an error.

The function is something like that

<script type="text/javascript">
function triggerLight() {
	//Do it
	return 1;
}
</script>

How I call them,

ExternalInterface.call("triggerLight");

On my own website, of course, not on NG, of course, because NG won't support such functions, so I use only the "get URL" thing to test here.

I do trace the thing,

trace(resultS);

And the TextField showed something when I did this.

if(ExternalInterface.available)
{
	//resultS = ExternalInterface.call("window.location.href.toString");
}
else
{
	resultS = "External Interface unavailable";
}

Which was the count variable. When it's not commented, it's "stuck".


Nav.. I'm the Nav!

Response to ExternalInterface .call "stuck" 2013-07-24 17:44:21


At 7/24/13 05:33 PM, TheNavigat wrote: I do trace the thing,

trace(resultS);

And the TextField showed something when I did this.

So this works.

if(ExternalInterface.available)
{
//resultS = ExternalInterface.call("window.location.href.toString");
}
else
{
resultS = "External Interface unavailable";
}

Which was the count variable. When it's not commented, it's "stuck".

And I told you how to replace that with As3.

Again, what's you question/problem?
Your calls to ExternalInterface work, except one which can be replaced by As3.

Response to ExternalInterface .call "stuck" 2013-07-24 17:53:44


At 7/24/13 05:44 PM, milchreis wrote:
At 7/24/13 05:33 PM, TheNavigat wrote: I do trace the thing,

trace(resultS);

And the TextField showed something when I did this.
So this works.

if(ExternalInterface.available)
{
//resultS = ExternalInterface.call("window.location.href.toString");
}
else
{
resultS = "External Interface unavailable";
}

Which was the count variable. When it's not commented, it's "stuck".
And I told you how to replace that with As3.

Again, what's you question/problem?
Your calls to ExternalInterface work, except one which can be replaced by As3.

"This" bypasses the ExternalInterface method "stuck" case, but ExternalInterface.call itself still doesn't work.

And what needs to be replaced by AS3? Everything here looks AS3 for me :/


Nav.. I'm the Nav!

Response to ExternalInterface .call "stuck" 2013-07-24 18:13:43


I guess I'm getting a little bit nearer. I took a copy of the example class in ExternalInterface documentation and implemented it. I got stuck with this error. "A SecurityError occurred: Error #2060". Still trying to figure out how to bypass it.


Nav.. I'm the Nav!

Response to ExternalInterface .call "stuck" 2013-07-24 18:18:04


At 7/24/13 05:53 PM, TheNavigat wrote: "This" bypasses the ExternalInterface method "stuck" case, but ExternalInterface.call itself still doesn't work.

Could you please finally clearly point out what is working and what is not working?

In the following quote, you state that you can successfully call a JS function via ExternalInterface:

At 7/24/13 05:33 PM, TheNavigat wrote: The function is something like that

<script type="text/javascript">
function triggerLight() {
//Do it
return 1;
}
</script>

How I call them,

ExternalInterface.call("triggerLight");

On my own website, of course, not on NG, of course, because NG won't support such functions, so I use only the "get URL" thing to test here.

I do trace the thing
And what needs to be replaced by AS3? Everything here looks AS3 for me :/

"window.location.href.toString" is not As3.

Response to ExternalInterface .call "stuck" 2013-07-24 18:45:39


At 7/24/13 06:18 PM, milchreis wrote:
At 7/24/13 05:53 PM, TheNavigat wrote: "This" bypasses the ExternalInterface method "stuck" case, but ExternalInterface.call itself still doesn't work.
Could you please finally clearly point out what is working and what is not working?

In the following quote, you state that you can successfully call a JS function via ExternalInterface:
At 7/24/13 05:33 PM, TheNavigat wrote: The function is something like that

<script type="text/javascript">
function triggerLight() {
//Do it
return 1;
}
</script>

How I call them,

ExternalInterface.call("triggerLight");

On my own website, of course, not on NG, of course, because NG won't support such functions, so I use only the "get URL" thing to test here.

I do trace the thing
And what needs to be replaced by AS3? Everything here looks AS3 for me :/
"window.location.href.toString" is not As3.

Okay, again.

I need to call JavaScript methods. Until now, I did not get that to work. More details is that the game gets "stuck" on the line of the ExternalInterface.call. Nothing, at all, written after it, is processed. I referred to commenting it to show how I understood that the game gets stuck there.

"window.location.href.toString" is a JavaScript function, not AS3. ExternalInterface.call is supposed to call JavaScript.

Sorry for the misunderstanding ._. I hope that made it clearer.


Nav.. I'm the Nav!

Response to ExternalInterface .call "stuck" 2013-07-24 19:21:34


Ok

At 7/24/13 06:45 PM, TheNavigat wrote: I need to call JavaScript methods. Until now, I did not get that to work.

So let's get this working.

You mentioned you get a Security error, this happens when you try to access something in a different sandbox.

Just to make sure we're talking about the same thing (there are multiple examples), post or link to the example that you tried including the Actionscript and html code that embeds the .swf file.

"window.location.href.toString" is a JavaScript function, not AS3. ExternalInterface.call is supposed to call JavaScript.

You can replace that JS with As3, so there's no need for this call to ExternalInterface.

Response to ExternalInterface .call "stuck" 2013-07-24 19:33:45


At 7/24/13 07:21 PM, milchreis wrote: Ok

At 7/24/13 06:45 PM, TheNavigat wrote: I need to call JavaScript methods. Until now, I did not get that to work.
So let's get this working.

You mentioned you get a Security error, this happens when you try to access something in a different sandbox.

Just to make sure we're talking about the same thing (there are multiple examples), post or link to the example that you tried including the Actionscript and html code that embeds the .swf file.

"window.location.href.toString" is a JavaScript function, not AS3. ExternalInterface.call is supposed to call JavaScript.
You can replace that JS with As3, so there's no need for this call to ExternalInterface.

Aha, I see. I still need ExternalInterface for calling the lights functions, so let's just keep it there as a test. I still need ExternalInterface working.

For the example, I tried to put my own code aside and use Adobe's example for now, get it working, and then try my own code. http://help.adobe.com/en_US/FlashPlatform/reference/actionsc ript/3/flash/external/ExternalInterface.html , the end of the page. text starting with "ExternalInterfaceExample.as". The HTML file is below it in the same page. The result was the mentioned error above, displayed on screen. I didn't edit anything, the code was all from Adobe. Just edited the SWF file name in the HTML file, that's all.


Nav.. I'm the Nav!

Response to ExternalInterface .call "stuck" 2013-07-25 05:03:37


At 7/24/13 07:33 PM, TheNavigat wrote: The result was the mentioned error above, displayed on screen.

Did you try the recommended steps described in the call() documentation?

http://help.adobe.com/en_US/FlashPlatform/reference/actionsc ript/3/flash/external/ExternalInterface.html#call%28%29

Response to ExternalInterface .call "stuck" 2013-07-25 09:27:25


At 7/25/13 05:03 AM, milchreis wrote:
At 7/24/13 07:33 PM, TheNavigat wrote: The result was the mentioned error above, displayed on screen.
Did you try the recommended steps described in the call() documentation?

http://help.adobe.com/en_US/FlashPlatform/reference/actionsc ript/3/flash/external/ExternalInterface.html#call%28%29

Yes I did, and it didn't work.

However, I've just installed ApachePHPMySQL, made a simple userdir, made a symlink to my game, ran the thing, and BOOM, it worked! With Adobe example code though, didn't test mine yet. Will test it later.

For those searching for the same problem, the problem is opening the file locally, in other words, having "file://" in the address. Try uploading it somewhere or installing Apache (as I did) and it will work as supposed to.

I'll test my own code and report what happened.


Nav.. I'm the Nav!