1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

‘document.getElementById(…)’ is null or not an object

Discussion in 'JavaScript' started by jeremybass, Mar 12, 2008.

  1. #1
    I was wondering if someone here would know why I get an error “document.pageLoading” is null or not an object if pageloading is a swf file?

    function toggleDiv(divid){
    if(document.getElementById(divid).style.display == ‘none’){
    document.getElementById(divid).style.display = ‘block’;
    document.pageLoading.TCallLabel(”/”,”restart_function”);
    }else{
    document.getElementById(divid).style.display = ‘none’;
    }
    }

    any help would be great… i’m just trying to call a function in action script when the div is toggled by the javascript… thanks

    ****edit****

    Also now i get ‘document.getElementById(…)’ is null or not an object

    Why?
    i want to be error free
    any ideas?
     
    jeremybass, Mar 12, 2008 IP
  2. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to look at whatever value you are passing to the function under the variable name "divid". Either there is no object with the name specified, or you are passing a blank value.

    To debug the javascript function, just put the following statement as the first line of the function:
    alert("[" + divid + "]"); return false;

    This will display a message box with whatever value was passed to it in between brackets. If two empty brackets appear [] then you know the value passed was blank.

    Also - I don't work with Flash so I can't be sure, but you might want to refer to the pageLoading object using getElementById, such as document.getElementById("pageLoading").
     
    vpguy, Mar 12, 2008 IP
  3. jeremybass

    jeremybass Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is the trigger...
    <a href="http://www.sjrmc.org/St_Joe_Core/" target="_self" onMouseDown="javascript:toggleDiv('hideMe3')"></a>
    Code (markup):
    So i put in
    alert("[" + divid + "]"); return false;
    Code (markup):
    and i get [hideMe3]... that is right... and it always functioned but i am still getting that error... may-be it is the flash call? ... ok it is now i just checked... :confused:

    on the flash call i was told the TCallLabel is the way to do it as it is the newest and most stable? so i was told...
    document.pageLoading.TCallLabel(”/”,”restart_function”);
    Code (markup):
    I need to call the function 'restart_function' in side the flash movie... If you know how i'm totly open for ideas... thank you for the hand...
     
    jeremybass, Mar 13, 2008 IP
  4. jeremybass

    jeremybass Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So i have had not much luck on this yet... does anyone have ideas on the best why to call a function from flash through js?
     
    jeremybass, Mar 14, 2008 IP
  5. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    vpguy, Mar 14, 2008 IP
  6. jeremybass

    jeremybass Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i know i keep going back on this... i try to take out the line... document.pageLoading.TCallLabel(”/”,”restart_function”); and i still see the document.getElementById(…)... this is pluzzeling to me... may-be i should fix that first then move to the flash side... plus i'v look at the first 5-6 pages and they are all places i'v been to... :p sucks lol... thank you for the help... i hope you stick it out with me on this... i sure need the help... have a great day...
     
    jeremybass, Mar 14, 2008 IP
  7. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Do you have a div with id="hideMe3" ? Check the markup code to ensure that you have named it properly.

    Also check other objects which trigger the same javascript function. You should work that problem out before working on the Flash problem.
     
    vpguy, Mar 14, 2008 IP
  8. jeremybass

    jeremybass Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    so i figured it out all i had to do was change
    function toggleDiv(divid){
    if(document.getElementById(divid).style.display == 'none'){
    document.getElementById(divid).style.display = 'block';
    document.pageLoading.TCallLabel('/','restart_function');
    }else{
    document.getElementById(divid).style.display = 'none';
    }
    }
    to

    <!--
    function toggleDiv(divid){
    if(document.getElementById(divid).style.display == 'none'){
    document.getElementById(divid).style.display = 'block';
    document.pageLoading.TCallLabel('/','restart_function');
    }else{
    document.getElementById(divid).style.display = 'none';
    }
    }
    //-->



    I don't know why it worked... but it did... but it brought out an error after the click... document.pageLoading.TCallLabel('/','restart_function');
    gofig on that

    Have any ideas on this?... pageLoading is a swf and 'restart_function' is a function in actioscript... I've look for ever one this and talked to alot of people and this is best that i've gotton on this area... thought it was working before... lol... thank you for the help...
     
    jeremybass, Mar 14, 2008 IP
  9. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I don't either... that makes no sense to me. I never use comment tags in my scripts and they work perfectly fine.

    I've never used Flash in my life so this is just speculation, but I have 2 ideas which you might want to try separately and then both at the same time to see if it fixes the problem:

    1) Change document.pageLoading to document.getElementById("pageLoading")
    2) Change 'restart_function' to 'restart_function()'
    3) Try both 1 and 2 together

    No guarantees though, I know nothing about Flash.

    I just had a thought - is it possible that the Javascript function is trying to call the Flash function too early? What you might need to do is have the SWF call a Javascript function once it finishes loading, and then have that Javascript function callback the SWF with the restart_function. My thought is that if the document.pageLoading statement is being executed before the SWF is fully loaded, it might be crapping out and giving you that error? Just a thought.

    And here's a page with information that looks mighty helpful: http://www.thescripts.com/forum/thread694359.html
     
    vpguy, Mar 15, 2008 IP
  10. jeremybass

    jeremybass Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Well, I'd sure like to know why the comment tags worked, the only reason I tried it was because I saw it in some other script. I know php, action script, just not much JavaScript.

    I don't think that could be the case as why the flash works is that when I Ctrl click a link I see the loading pop up...

    How it works: Click the link
    1.) (js)unhide div, (as)play first movie in first frame
    2.) and then after 20secs in the flash movie stops and goToAndStop on a frame with a time out movie
    3.) the current movie on frame 2 then goToAndStop frame 3 with a reset function and a (as)JavaScript that is the trigger back to (js)JavaScript to hide the div... so if you click on a link again you should see it start all over again... It did work as it is before... but then i did something and didn't realize that it stop until to late... the hide from (as) works... it's just the call to the as from the js that anit working...???

    I'll take a look at the link and get back.... thanks :)
     
    jeremybass, Mar 15, 2008 IP
  11. jeremybass

    jeremybass Guest

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    ok so sometimes i'm dumb...
    document.pageLoading.TCallLabel('/','restart_function');
    Code (markup):
    worked once... Soo why did it stop... well the AS founction 'restart_function' is not in the swf... I uploaded the old outputed swf over the new one that has the function in it... like i said i'm stright dubm sometimes lol... I'll have to wait untill Mon to confirm but i think this is 100% working now and good to go... when I confirm I'll post it up

    If someone could tell me why the script works with the (function within comment tags) and not (function without comment tags) that'd be helpfull... The only thing that i can think is the IE is doing something? I don't get the error in FF... ideas would be great as i'm sure anyone else that fall in this trap would want to understand as well as just fixing it like i do... :) thanks for sticking it out vpguy
     
    jeremybass, Mar 15, 2008 IP
  12. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Hard to say. What doctype are you using? I can't imagine that would affect it but it's possible. Also what version of IE are you using? It might be helpful to see the code which surrounds the script portion that contains the function as well.
     
    vpguy, Mar 15, 2008 IP