HOW TO: Find the Top & Left window offset of an embed'ed [Flash] object.

Discussion in 'Javascript' started by gsb, Nov 22, 2003.

  1. gsb

    gsb Guest

    I'd like to get the offset coordinates, top & left, of an embedded Flash
    movie.

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.ca
    b#version=7,0,14,0"
    id="tabMenu" width="720" height="420">
    <param name="movie" value="tabMenu.swf">
    <param name="menu" value="false">
    <param name="quality" value="best">
    <param name="wmode" value="opaque">
    <param name="base" value="file://C:/WINDOWS/Desktop/031122a/">
    <param name="bgcolor" value="#FFFFFF">
    <param name="allowScriptAccess" value="sameDomain">
    <embed id="tabMenu" name="tabMenu" src="tabMenu.swf"
    menu="false" quality="best" wmode="opaque"
    base="file://C:/WINDOWS/Desktop/031122a/" bgcolor="#FFFFFF"
    swLiveConnect="true" allowScriptAccess="sameDomain"
    width="720" height="420"
    type="application/x-shockwave-flash"
    pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
    </object>

    I'm using Netscape 7.1.

    document.tabmenu.offsetLeft and document.tabmenu.offsetTop don't seem to do
    it correctly.

    Any help will be appreciated.

    Thanks

    gsb
    gsb, Nov 22, 2003
    #1
    1. Advertising

  2. gsb

    DU Guest

    Re: HOW TO: Find the Top & Left window offset of an embed'ed [Flash]object.

    gsb wrote:
    > I'd like to get the offset coordinates, top & left, of an embedded Flash
    > movie.
    >
    > <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    >
    > codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.ca
    > b#version=7,0,14,0"
    > id="tabMenu" width="720" height="420">
    > <param name="movie" value="tabMenu.swf">
    > <param name="menu" value="false">
    > <param name="quality" value="best">
    > <param name="wmode" value="opaque">
    > <param name="base" value="file://C:/WINDOWS/Desktop/031122a/">
    > <param name="bgcolor" value="#FFFFFF">
    > <param name="allowScriptAccess" value="sameDomain">
    > <embed id="tabMenu" name="tabMenu" src="tabMenu.swf"
    > menu="false" quality="best" wmode="opaque"
    > base="file://C:/WINDOWS/Desktop/031122a/" bgcolor="#FFFFFF"
    > swLiveConnect="true" allowScriptAccess="sameDomain"
    > width="720" height="420"
    > type="application/x-shockwave-flash"
    > pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
    > </object>
    >
    > I'm using Netscape 7.1.
    >
    > document.tabmenu.offsetLeft and document.tabmenu.offsetTop don't seem to do
    > it correctly.
    >


    document.getElementById("tabMenu").offsetLeft
    and
    document.getElementById("tabMenu").offsetTop
    will give the offset values relative to its offsetParent, not necessarly
    relative to the document or the browser viewport. offset[Left/Top] is
    always relative to the offsetParent node, the node which acts like the
    positional context of inner nodes ("offsetParent node: closest
    positioned containing element within the DOM node containment hierarchy").

    To reference an element, use document.getElementById or another DOM 1
    method.

    I recommend you read these:

    Using Web Standards in Your Web Pages:
    Accessing Elements with the DOM
    http://www.mozilla.org/docs/web-developer/upgrade_2.html#dom_access

    Updating DHTML Web Pages for next generation browsers
    http://devedge.netscape.com/viewsource/2001/updating-dhtml-web-pages/


    DU

    > Any help will be appreciated.
    >
    > Thanks
    >
    > gsb
    >
    >
    DU, Nov 22, 2003
    #2
    1. Advertising

  3. gsb

    gsb Guest

    Basically, that is what I was trying:

    function getOffsetLeft(o) { var ol=o.offsetLeft;
    while((o=o.offsetParent)!=null) { ol+=o.offsetLeft;} return ol }
    function getOffsetTop (o) { var ot=o.offsetTop;
    while((o=o.offsetParent)!=null) { ot+=o.offsetTop;} return ot }
    function libGetLoc(o) { var c=new
    Object();c.x=getOffsetLeft(o);c.y=getOffsetTop(o);return c }

    loc = libGetLoc( document.getElementById("tabMenu") );

    In Netscape it gives me a wrong 'Top' number, way off. IE is correct.

    If I surround all with a DIV tag and get the location of the that tag, both
    are correct.

    Any thoughts?

    Thanks for you time and help.

    gsb
    gsb, Nov 22, 2003
    #3
  4. gsb

    DU Guest

    Re: HOW TO: Find the Top & Left window offset of an embed'ed [Flash]object.

    gsb wrote:
    > Basically, that is what I was trying:
    >
    > function getOffsetLeft(o) { var ol=o.offsetLeft;
    > while((o=o.offsetParent)!=null) { ol+=o.offsetLeft;} return ol }
    > function getOffsetTop (o) { var ot=o.offsetTop;
    > while((o=o.offsetParent)!=null) { ot+=o.offsetTop;} return ot }
    > function libGetLoc(o) { var c=new
    > Object();c.x=getOffsetLeft(o);c.y=getOffsetTop(o);return c }
    >
    > loc = libGetLoc( document.getElementById("tabMenu") );
    >
    > In Netscape it gives me a wrong 'Top' number, way off. IE is correct.



    I don't see how you call your function. I don't see any of your markup
    code. No specifics. No url.
    "way off" could mean 50px, could mean 500px or could mean 1000px. Here,
    I don't even have an idea of magnitude.

    >
    > If I surround all with a DIV tag and get the location of the that tag, both
    > are correct.
    >


    I don't see any of what you say in your posted messages. So I can not
    follow you or reproduce what you see. An url would have been helpful.

    > Any thoughts?
    >
    > Thanks for you time and help.
    >
    > gsb
    >
    >


    Is your markup code valid, validated?
    Is your code triggering backward compatible rendering mode in MSIE 6 for
    windows?
    In your initial post, you have 2 distinct elements (object and embed)
    with the same id="tabMenu"; now, this is a validation error...
    "(...) must be unique in a document."
    http://www.w3.org/TR/html401/struct/global.html#adef-id
    most likely having consequences on your script function correct behavior.
    It's very difficult to recommend anything more without being able to
    examine the whole code.

    DU
    DU, Nov 24, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lance Riedel

    Translated Offset to Source Offset

    Lance Riedel, Oct 14, 2003, in forum: XML
    Replies:
    2
    Views:
    498
    Patrick TJ McPhee
    Oct 15, 2003
  2. Pieter Van Waeyenberge
    Replies:
    1
    Views:
    166
    Pieter Van Waeyenberge
    Feb 9, 2004
  3. Replies:
    1
    Views:
    147
    Matt Kruse
    Mar 15, 2006
  4. Stevo
    Replies:
    10
    Views:
    284
    Thomas 'PointedEars' Lahn
    Mar 27, 2008
  5. Roy Smith
    Replies:
    4
    Views:
    263
    Roy Smith
    Jan 27, 2013
Loading...

Share This Page