Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

flash - Security Error when trying to call ActionScript function from JS

I have a little test swf to test calling an ActionScript(3.0) function from JavaScript. I am using the Flash documentation as a reference: (http://www.adobe.ca/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000340.html) When the page loads I am presented with a Flash Player error:

SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller file: c:/externalinterface.swf cannot access file: c:myhtml.html
at flash.external::ExternalInterface$/_initJS()
    at flash.external::ExternalInterface$/addCallback()
    at externalinterface_fla::MainTimeline/frame1()

This is the ActionScript:

 import flash.external.ExternalInterface

function callMe(name:String):String{

    return "busy signal";

    }

    ExternalInterface.addCallback("myFunction",callMe);

And the JS:

<script type="text/javascript" language="javascript">
    function callSwf() {
        var callResult = flashObject.myFunction("Nick");
        alert(callResult);
    }   

</script>

Finally the HTML Object:

<object width="550" height="400">
<param name="movie" value="externalinterface.swf">
<embed src="externalinterface.swf" width="550" height="400">
</embed>
</object>

How do we work around this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

if you test online or localhost, it should work if you had the param allowscriptaccess="true" like dome said. If you are testing with file:// protocol you need to allow your drive in the flash player security options.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...