views:

328

answers:

2

I have the need to change a variable in a child flash file. The setup is a parent flash file has called a child flash, and placed it in movieclip. I can send a variable using Javascript to the parent flash file, but not directly to the child flash file. Is there a way that I can access the child flash file directly with javascript? Or do I need to send the variable to the parent flash file, and then have the parent send the variable to the child flash file? Is there a sort of dot notation that I can use with javascript to get to the child flash file without first accessing the parent, when the child is added to the parent using the loadclip function in flash?

A: 

I have never tried personally, but I would assume you can use the ExternalInterface class in your child SWF just as you would if it were in the parent. For example,

// INSIDE CHILD SWF SOMEWHERE

ExternalInterface.addCallBack("doSometing", doSomething);

function doSomething(...args) {

}
sberry2A
A: 

yeah..

from flash 8 you can use ExternalInterface. it is bidirectional.

in your first SWF(fla) you call the javascript function with paramaters like:

in SWF -->

ExternalInterface.call("setValue", form, field, publish);

in javascript

function setValue(form, field, publish) {
    alert(form + " " + field + " " + publish)
}

for bidirectional to your parent SWF you can do something like this in your parent SWF:

import flash.external.ExternalInterface;
function getValueFromJavaScript(strTmp){  

 textMC.text = "Value received from JS" + str;

}

ExternalInterface.addCallback("sendValueToFlash", this, getValueFromJavaScript);

in Javascript:

 <script >  
   function getFlashMovie(movieName) {
       var isIE = navigator.appName.indexOf("Microsoft") != -1;
       return (isIE) ? window[movieName] : document[movieName];
   }  
   function formSend() {
       var text = "Hello Flash";
       getFlashMovie("ExternalInterfaceExample").sendValueToFlash(text);
   }
   </script>
michel