Marius van Witzenburg "Learned my lesson in life, now setting my action to stay in life."

24Jun/100

Control a flash movie from javascript and javascript from flash movies

Personally I dislike the usage of Flash in my websites but our clients request a lot that they want animations. Now it happens that they want the animation to act upon an action to a non-flash object. This can be difficult if you have no idea how to do that. If you read below, you should have no problem with getting this job done :-)

Control your Flash Movie from Javascript:

// Play movie
document.getElementById('myFlashMovie').Play();
// Stop movie
document.getElementById('myFlashMovie').StopPlay();
// Rewind movie to beginning
document.getElementById('myFlashMovie').Rewind();
// Goto next frame of MovieClip
document.getElementById('myFlashMovie').TGetProperty(nameOfTargetMovieClip, propertyIndex);
// Goto next frame of TimeLine
document.getElementById('myFlashMovie').GotoFrame(frameNum);
// Zoom in or out the flash movie
document.getElementById('myFlashMovie').Zoom(relative percentage);
// Set variable and make it available via ActionScript
document.getElementById('myFlashMovie').SetVariable(variableName, variableValue);
// Get variable for usage in JavaScript
var myVariable = document.getElementById('myFlashMovie').GetVariable(variableName);

To control Javascript functions you can call it like this:

getURL("javascript:naam_van_functie();");

For some more information about these methods, please check out the Adobe website.

I hope this helps you out with getting that Flash Movie behave like you want it to ;-)