SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member zebra242's Avatar
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face 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.



    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:

    Added another js:
    Code:
    <!-- 
    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          oldonload();
          func();
        }
      }
    }
    addLoadEvent(function GotoLabelStart()
    {
    	var flashMovie=getFlashMovieObject("myFlashMovie");
    	flashMovie.TGotoLabel("/", "start");
    }
    );
    //-->
    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.
    Last edited by zebra242; Oct 10, 2007 at 08:59.

  2. #2
    SitePoint Member zebra242's Avatar
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Trial and error

    All these scripts I tried and failed to work in Safari, FF, Netscape and Opera:

    1.
    Code:
    <body onload="GotoLabelTerug();">
    2.
    Code:
    <!-- 
    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          oldonload();
          func();
        }
      }
    }
    addLoadEvent(function GotoLabelTerug()
    {
    	var flashMovie=getFlashMovieObject("myFlashMovie");
    	flashMovie.TGotoLabel("/", "terug");
    }
    );
    //-->
    3.
    Code:
    <!-- 
    window.onload=function GotoLabelTerug()
    {
    	var flashMovie=getFlashMovieObject("myFlashMovie");
    	flashMovie.TGotoLabel("/", "terug");
    }
    //-->
    4.
    Code:
    <script type="text/javascript">
    function load()
    {
    var flashMovie=getFlashMovieObject("myFlashMovie");
    	flashMovie.TGotoLabel("/", "terug");
    }
    </script>
    </head>
    <body onload="load()">
    5.
    Code:
    <!--
    function addEvent(obj, evType, fn){ 
     if (obj.addEventListener){ 
       obj.addEventListener(evType, fn, false); 
       return true; 
     } else if (obj.attachEvent){ 
       var r = obj.attachEvent("on"+evType, fn); 
       return r; 
     } else { 
       return false; 
     } 
    }
    addEvent(window, 'load', GotoLabelTerug);
    //-->
    6.
    Code:
    <!--
    function addEvent(obj, evType, fn){ 
     if (obj.addEventListener){ 
       obj.addEventListener(evType, fn, false); 
       return true; 
     } else if (obj.attachEvent){ 
       var r = obj.attachEvent("on"+evType, fn); 
       return r; 
     } else { 
       return false; 
     } 
    }
    addEvent(document, 'load', GotoLabelTerug);
    //-->
    7.
    Code:
    <!--window.onload=function(){load();}
    function load(){
      movie=getFlashMovieObject();
      movie.TGotoLabel("/", "terug"); 
    }//-->

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try without the HTML comments. ( <!-- and //-->) You don't need them, especially if you're putting this in an external file. If this is in an external JS file, this is almost certainly why it isn't working.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •