Marius van Witzenburg We fight for our survival, we fight!

14Jun/110

How to control a Flash movie from Javascript and use Javascript from Flash movies

Posted by mariusvw

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:

ActionScript 1/2

getURL("javascript:name_of_your_function();");

ActionScript 3 direct call

var url:String = "javascript:name_of_your_function();";
var request:URLRequest = new URLRequest(url);
try {
  navigateToURL(request);
} catch (e:Error) {
  trace("Error occurred!");
}

ActionScript 3 event mouse click call

movieClipName.addEventListener(MouseEvent.CLICK, callLink);
function callLink:void {
  var url:String = "javascript:name_of_your_function();";
  var request:URLRequest = new URLRequest(url);
  try {
    navigateToURL(request);
  } catch (e:Error) {
    trace("Error occurred!");
  }
}

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 ;-)

18May/100

How to trap or catch Keyboard Interrupt in Bash on Linux/FreeBSD

Posted by mariusvw

This is a simple code snippet, I think it explains it self.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
 
myCleanup() {
  rm -f /myapp/tmp/mylog
  return $?
}
 
myExit() {
  echo -en "n*** Exiting ***n"
  myCleanup
  exit $?
}
 
trap myExit SIGINT
 
# main loop
while true
do
    echo -n "Enter your name: "
    read x
    echo "Hello $x"
done

If you have any questions, just ask :-)