469,626 Members | 1,010 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

onLoad Function in Javascript

I'm working to get the onLoad function of a javascript to work:
the script allows form buttons in html to refer to labeled frames in flash. Which works fine.

Now I want to add onLoad functionality to force the flash file to jump to a labeled frame on load.

This is the Javascript in the head of the html file:

Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. function getFlashMovieObject(movieName)
  3. {
  4.   if (window.document[movieName]) 
  5.   {
  6.     return window.document[movieName];
  7.   }
  8.   if (navigator.appName.indexOf("Microsoft Internet")==-1)
  9.   {
  10.     if (document.embeds && document.embeds[movieName])
  11.       return document.embeds[movieName]; 
  12.   }
  13.   else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  14.   {
  15.     return document.getElementById(movieName);
  16.   }
  17. }
  18.  
  19. function GotoLabelStart()
  20. {
  21.     var flashMovie=getFlashMovieObject("myFlashMovie");
  22.     flashMovie.TGotoLabel("/", "start");
  23. }
  24. //-->
  25.  
By using a form and form buttons the script jumps to a frame labelled 'Start'.

Expand|Select|Wrap|Line Numbers
  1. <input type="button" value="Start" name="Start" onclick="GotoLabelStart();" />
  2.  
I tried several solutions I've found on the net to make the onLoad function to work, please note that it needs to work for Safari on Mac aswell.

SOLUTIONS tried and not working:

1. <body onload="GotoLabelStart();">

2. Added another js:
Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. function addLoadEvent(func) {
  3.   var oldonload = window.onload;
  4.   if (typeof window.onload != 'function') {
  5.     window.onload = func;
  6.   } else {
  7.     window.onload = function() {
  8.       oldonload();
  9.       func();
  10.     }
  11.   }
  12. }
  13.  
  14. addLoadEvent(GotoLabelStart);
  15. addLoadEvent(function GotoLabelStart()
  16. {
  17.     var flashMovie=getFlashMovieObject("myFlashMovie");
  18.     flashMovie.TGotoLabel("/", "start");
  19. }
  20. );
  21. //-->
  22.  
3. Another js I tried was :
Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. window.onload=function GotoLabelStart()
  3. {
  4.     var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "start");
  6. }
  7. //-->
  8.  
4. Another thing I tried was adding :
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function load()
  3. {
  4. var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "terug");
  6. }
  7. </script>
  8. </head>
  9. <body onload="load()">
  10.  
5. Another thing I tried:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/JavaScript">
  2. <!--
  3. function GotoLabelStart() {
  4. var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "start");
  6. }
  7. //-->
  8. </script>
  9. </head>
  10.  
  11. <body onload="GotoLabelStart();">
  12.  
6. Another try:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/JavaScript">
  2. <!--
  3. window.onload=function(){
  4.  function GotoLabelStart() {
  5. var flashMovie=getFlashMovieObject("myFlashMovie");
  6.     flashMovie.TGotoStart("/", "start");
  7. }
  8. }
  9. //-->
  10. </script>
  11.  
7. Well, I tried ;-) Doesn't any one know a solution that actually works? The script needs to force the flash file to jump to a labeled frame onLoad.
Oct 10 '07 #1
1 7848
All these scripts I tried and won't work in Safari, Netscape, Opera and Firefox:

1.
Expand|Select|Wrap|Line Numbers
  1. <body onload="GotoLabelTerug();">
2.
Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. function addLoadEvent(func) {
  3.   var oldonload = window.onload;
  4.   if (typeof window.onload != 'function') {
  5.     window.onload = func;
  6.   } else {
  7.     window.onload = function() {
  8.       oldonload();
  9.       func();
  10.     }
  11.   }
  12. }
  13. addLoadEvent(function GotoLabelTerug()
  14. {
  15.     var flashMovie=getFlashMovieObject("myFlashMovie");
  16.     flashMovie.TGotoLabel("/", "terug");
  17. }
  18. );
  19. //-->
  20.  
3.
Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. window.onload=function GotoLabelTerug()
  3. {
  4.     var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "terug");
  6. }
  7. //-->
4.
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function load()
  3. {
  4. var flashMovie=getFlashMovieObject("myFlashMovie");
  5.     flashMovie.TGotoLabel("/", "terug");
  6. }
  7. </script>
  8. </head>
  9. <body onload="load()">
5.
Expand|Select|Wrap|Line Numbers
  1. <!--
  2. function addEvent(obj, evType, fn){ 
  3.  if (obj.addEventListener){ 
  4.    obj.addEventListener(evType, fn, false); 
  5.    return true; 
  6.  } else if (obj.attachEvent){ 
  7.    var r = obj.attachEvent("on"+evType, fn); 
  8.    return r; 
  9.  } else { 
  10.    return false; 
  11.  } 
  12. }
  13. addEvent(window, 'load', GotoLabelTerug);
  14. //-->
6.
Expand|Select|Wrap|Line Numbers
  1. <!--
  2. function addEvent(obj, evType, fn){ 
  3.  if (obj.addEventListener){ 
  4.    obj.addEventListener(evType, fn, false); 
  5.    return true; 
  6.  } else if (obj.attachEvent){ 
  7.    var r = obj.attachEvent("on"+evType, fn); 
  8.    return r; 
  9.  } else { 
  10.    return false; 
  11.  } 
  12. }
  13. addEvent(document, 'load', GotoLabelTerug);
  14. //-->
7.
Expand|Select|Wrap|Line Numbers
  1. <!--window.onload=function(){load();}
  2. function load(){
  3.   movie=getFlashMovieObject();
  4.   movie.TGotoLabel("/", "terug"); 
  5. }//-->
Oct 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by David Virgil Hobbs | last post: by
2 posts views Thread by laredotornado | last post: by
20 posts views Thread by Mark Anderson | last post: by
2 posts views Thread by WGW | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.