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

G

gsb

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
 
D

DU

gsb said:
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
 
G

gsb

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
 
D

DU

gsb said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top