Further to my previous post ...and thanks so much for the responses .... This is the real situation I'm trying to resolve. Just need to call a swf from javascript to move the swf on to another time frame.
AS3
Import flash.external.ExternalInterface;
function moveOn (frame:int ) : void
{
gotoAndPlay (frame);
}
ExternalInterface.addCallback("myjsFunction", moveOn);
JS
<script language="JavaScript">
function sendtoSwf (frame){
MyMovie.myjsFunction(frame);
}
</script>
...
<object id="MyMovie"...>
...
<param name="allowScriptAccess" value="always" />
....
<embed name="MyMovie".../>
</object>
HTML JS trigger
<a href onclick=”javascript : sendtoSwf(25);”> click here </a>
If someone could please clarify, since I only want to trigger swf from js, do I maybe not need the ...addCallback(...) line ? Should it actually be just a ...Call(...)? I havent quite grassped the Internal Interface idea yet. In my html click trigger Im trying to pass an integer value which is the actual frame I 开发者_C百科want the swf to move to, I'm not sure if the trigger should link to the "sendtoSwf" function or the "myjsFunction" ...do I not need a reference in js to the actual name of the as3 function that moves the frame?(i.e. moveOn) Any clarifacation would be GREATLY appreciated. Thanks in anticipation. Ed
For anyone interested this is what worked:
<script type="text/javascript">
//checking which browser used
function getFlashMovieObject(movieName){
if (window.document[movieName]){
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1){
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else{
return document.getElementById(movieName);
}
}
//code that sends frame no to flash
function sendtoSwf(numb){
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.sendToFlash(numb);
}
</script>
And the action script
import flash.external.ExternalInterface;
ExternalInterface.addCallback("sendtoFlash", getFromJavaScript);
function getFromJavaScript(frame:int):void {
gotoAndPlay(frame);
}
You definitely need the addCallback function , but you also need to check that Javascript is ready to communicate with Actionscript. Have a look at the docs, the example is fairly detailed and should give you the information you need.
check the External Interface class http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/
精彩评论