Click to See Complete Forum and Search --> : ExternalInterface troubles with callBack!

04-23-2007, 11:22 PM
Alright guys, I have been researching the ExternalInterface for the past couple of days, and I think it would really be good for what I'm trying to do with a project of mine.

In this project, the user reads information about a subject, then is quizzed at the end. The quiz is made in flash, and works 100% fine (it imports an XML file and then builds itself accordingly). However, the way I'm doing it now, I would have to compile a new flash movie to reference each XML file, and obviously that is a waste of time. On the quiz pages, I want to make javascript code that will, upon loading of the page, call that function in the flash movie to load the XML file that has the questions about the section. How can I do this? I am lost as to:

1) Where to put the Javascript
2) How to get the callBack to work (I know you can make a function external with the line ExternalInterface.callBack("myFuncForJava",null,flashFunction), but I do not know how to get JavaScript to reference my flash movie)

Any help on this would be MUCH appreciated. Thanks in advance :)

04-24-2007, 11:35 AM
Why don't you just import a parameter that indicates which XML document to call (done from your swf embed)? This would require you to set up a series a variables in your swf equal to each subject matter.

So, lets say you have four subjects: Math, English, Science, and History. If your wanting to load the Math quiz, in your embed you would pass the parameter Math with a value of true.

//Using swfObject to embed you movie your embed would look like this -
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("Quize.swf", "", "430", "225", "8", "");
/*-- To activate quiz set subject to "True" --*/
so.addVariable("Math", "true");
// ]]>
Then in your swf just establish a variable URL and set a series of cases or else(if) statements for each subject. If Math is == true then make URL = math.xml. And finally, when you load your XML object, just replace your url string with the variable "URL".

You could define each subject variable in a separate xml document but if you're only dealing with 3 or 4 subjects, that might be a bit overkill.

Hope I haven't confused the issue.

Best of luck!

04-24-2007, 03:42 PM
I have a few questions about that... first, don't you need to install certain files to the domain to use an SWFObject in Javascript? Secondly, it would be far better for me to have a function callBack into the Flash movie, because I'm actually developing a training module with different categories, and the types of categories can change at different times, so it would still require that I recompile to meet these new needs.

Do you know how I could get this working :) The callBack that is.

04-24-2007, 04:08 PM
...don't you need to install certain files to the domain to use an SWFObject in Javascript

Yes, there is one script you will need to reference. Info here: http://blog.deconcept.com/swfobject/

Sounds like your developing a SCORM - Sharable Object Reference Model: http://download.macromedia.com/pub/solutions/downloads/elearning/scorm_flashlo.pdf

Here info that should assist you with what you're looking to achieve:

Hope this helps.