0

So, I've been avoiding posting this question because of the shear amount of prior posts. I've tried several variations of the following code, and to no avail.

I'm using FireFox (latest), Flash Player (latest), AS3, and A couple lines of JavaScript.

Here's my AS3 :

import flash.external.*;

// Handling Count For External Refreshing

var count: Number = 0;
var countMax: Number = 3;

function countHandler(): void {
    if (count >= countMax) {
        trace("The count has reached the max " + countMax);
        ExternalInterface.call("refresh");
        count = 0;
    } else {
        trace("The Count is " + count)
        return;
    }
}

I've traced the count, the total, all that, so I know that the code is working. It even resets the count when it gets to 3

Here's the javascript :

<script language="JavaScript">
    function refresh() {
        window.location.reload();
    }
</script>

For giggles/testing, I added a button to the page to test that the above code is working...

<input type="button" value="Reload Page" onClick="refresh()">

When I press the button, it refreshes the page.

Is there something I'm missing? Why will the working AS3 Not refresh the page by triggering the working javascript?

When I click the button, it refreshes, when the code triggers via ActionScript, I'm unable to press any of the SWF buttons. So it's firing, but not actually refreshing the whole page.

Update July4th - Updated AS3 and Java - Still no Luck

10
  • But in your ActionScript code your are calling a refresh js function which in reality didn't exist ( at least in your posted code ) ! So your 1st code should be : ExternalInterface.call("reload");, try that and tell us what you get. Commented Jul 4, 2015 at 10:40
  • @akmozo I'll update the code I have right now. I tried what you said and it didn't work. The button is also using the same refresh() method. One Sec... Commented Jul 4, 2015 at 19:09
  • Firstly you should know that Java and JavaScript are two different languages ! For your question, I don't know what's your problem exactly, may be you have a security error, try to verify that using flash player debug version which you can get from here : adobe.com/support/flashplayer/downloads.html ... Commented Jul 4, 2015 at 22:04
  • I understand the two are different. I was pretty sure I installed the Debugger version already, but just went ahead and reinstalled it to be sure. I added a crossdomain.xml file to the project directory, as well as set <param name="allowScriptAccess" value="*" /> Commented Jul 4, 2015 at 23:31
  • 1
    For js communication you don't need a crossdomain.xml file and the allowscriptaccess should be always or other values but not *. For the debug, normally if you have a security ( or any other error ) you will get a message from the flash player. For more details about external interface take a look here. If you have always the problem, I will see it tomorrow because it's really late here. Commented Jul 5, 2015 at 0:17

1 Answer 1

1

Thanks to Akmozo for the help.

Set allowScriptAccess to always - NOT * Like the adobe tutorial says (bastards). The SWF can't have any hyphens or dashes. I had to set the file name to My.Test.File.fla so when I export/build it outputs the following flashContent

<div id="flashContent">
    <object type="application/x-shockwave-flash" data="My.Test.File.swf" width="1920" height="1080" id="My.Test.File" style="float: none; vertical-align:middle">
        <param name="movie" value="My.Test.File.swf" />
        ...
        <param name="allowScriptAccess" value="always" />
        ...
    </object>
</div>

More info on symbols in nomenclature - Here

Here is the ActionScript I used.

// Handling Count For External Refreshing
var count: Number = 0; //start count at 0
var countMax: Number = 3; //max whatever you need it to be
var isAvailable: Boolean = ExternalInterface.available; // checking if avail 

trace(isAvailable); 

function countHandler(): void {
    if (count >= countMax) {
        trace("The count has reached the max " + countMax); // Trace in flash 
        ExternalInterface.call("console.log", "testing..."); // Output to Console
        ExternalInterface.call("refresh"); //fire the refresh script
        count = 0; // reset the count
    } else {
        trace("The Count is " + count)
        return;
    }
}

Here is the java script. Placed in <head> below <style>

<script language="JavaScript">
        function refresh() {
            console.log("Try To Refresh");
            window.location.reload();
        }
  </script>

I had to create a crossdomain.xml file to allow access. I've tested the project several times with and without the crossdomain.xml and it without it, I get a security sandbox error. Not sure why allowScriptAccess="always" isn't working.

Conclusion So it appears that setting allowScriptAccess to * is a bad idea. I got that from one of Adobe's Security Sandbox tutorials (thanks Adobe). Also, passing "refresh();" through ExternalInterface.call looks for refresh arguments which there are none. The SWf file name but not use dashes - like this..

This... MyFileName.swf

Not this... My-File-Name.swf

This code is executing as expected. Thank you all for your input and help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.