By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,380 Members | 1,736 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,380 IT Pros & Developers. It's quick & easy.

Object Pointers

P: n/a
I'm trying to use object pointers to access/modify various properties of
various layers.
The problem i'm having is that pointers created within my functions dont
have world scope even though the variables used are world variables.

Script Example:
<script>
var lyr1, lyr2;
function initIE(){
lyr1 = layer1.style;
lyr2 = layer2.style;
lyr1.z = lyr1.zIndex;
lyr2.z = lyr2.zIndex;
};

function switcher(a){
lyr1.z = 9;
lyr2.z = 8;
a.style.zIndex = 11;
};
</script>

Now when switcher(a) is called lines 1 & 2 do not effect the 2 layer's
z-index while line 3 does what I want it to.
So I'm assuming that the object pointers created in initIE() are not given
world scope.
How do I rectify this?

TIA
S.Taylor
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Ralph??" <ra******@stis.net> writes:
I'm trying to use object pointers to access/modify various properties of
various layers.
The problem i'm having is that pointers created within my functions dont
have world scope even though the variables used are world variables. .... Now when switcher(a) is called lines 1 & 2 do not effect the 2 layer's
z-index while line 3 does what I want it to.
So I'm assuming that the object pointers created in initIE() are not given
world scope.
They are, but they don't work as you seem to expect them to.

After initIE, you have two object references, lyr1 and lyr2, each
pointing to a style object. Inside that style object is a property
called "z", which has nothing to do with the style of an element. It
currently holds the same value as the "zIndex" property of the same
element. Changing the "z" property does nothing to the "zIndex"
property.
How do I rectify this?


Forget the "z" property and change the two first lines of switcher to
lyr1.zIndex = 9;
lyt2.zIndex = 8;

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
"Ralph??" <ra******@stis.net> wrote in message
news:ba******************************@free.teranew s.com...
I'm trying to use object pointers to access/modify various
properties of various layers.
The problem i'm having is that pointers created within my
functions dont have world scope even though the variables
used are world variables. Script Example:
<script>
var lyr1, lyr2;
That will correctly define the two global variables.
function initIE(){
lyr1 = layer1.style;
Assuming that the fact that the function is called "initIE" indicates
that you don't expect to use this code on non-IE browsers and that a DOM
element exists with the ID "layer1" then this code will set the global
variable - lyr1 - to a reference to that element's - style - object.
Thus - lyr1 - is a reference to an object.
lyr2 = layer2.style;
lyr1.z = lyr1.zIndex;
As - lyr1 - is a reference to a - style - object and style objects do
not have a - z - property, the - lyr1.z - code will create a new
property on the element's style object. That new property will be set to
the value read from the - zIndex - property of that same - style -
object. However, the - zIndex - property of a - style object is usually
a string, so the new - z - property on the style object is assigned a
string value.
lyr2.z = lyr2.zIndex;
};

function switcher(a){
lyr1.z = 9;
Now you are re-setting the - z - property that you created on the -
style - object to a numeric value. This will have no consequences for
the displayed page because the - style - object has no interest in your
setting your own values to your own properties. If you want a - style -
object to react you need to be setting the value of the properties that
it understands, in this case - zIndex -. Try:-

lyr1.zIndex = 9;
lyr2.z = 8;
a.style.zIndex = 11;
};
</script>

<snip>
Jul 20 '05 #3

P: n/a

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:n0**********@hotpop.com...
"Ralph??" <ra******@stis.net> writes:
Forget the "z" property and change the two first lines of switcher to
lyr1.zIndex = 9;
lyt2.zIndex = 8;


Thank you, I realized , about 2 hours after posting, that you can't make an
object pointer to a property that contains a value, that the pointer will
be used as a variable, instead.

Jul 20 '05 #4

P: n/a

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:be*******************@news.demon.co.uk...
"Ralph??" <ra******@stis.net> wrote in message
news:ba******************************@free.teranew s.com...
I'm trying to use object pointers to access/modify various
properties of various layers.
The problem i'm having is that pointers created within my
functions dont have world scope even though the variables
used are world variables.

Script Example:
<script>
var lyr1, lyr2;


That will correctly define the two global variables.
function initIE(){
lyr1 = layer1.style;


Assuming that the fact that the function is called "initIE" indicates
that you don't expect to use this code on non-IE browsers and that a DOM
element exists with the ID "layer1" then this code will set the global
variable - lyr1 - to a reference to that element's - style - object.
Thus - lyr1 - is a reference to an object.
lyr2 = layer2.style;
lyr1.z = lyr1.zIndex;


As - lyr1 - is a reference to a - style - object and style objects do
not have a - z - property, the - lyr1.z - code will create a new
property on the element's style object. That new property will be set to
the value read from the - zIndex - property of that same - style -
object. However, the - zIndex - property of a - style object is usually
a string, so the new - z - property on the style object is assigned a
string value.
lyr2.z = lyr2.zIndex;
};

function switcher(a){
lyr1.z = 9;


Now you are re-setting the - z - property that you created on the -
style - object to a numeric value. This will have no consequences for
the displayed page because the - style - object has no interest in your
setting your own values to your own properties. If you want a - style -
object to react you need to be setting the value of the properties that
it understands, in this case - zIndex -. Try:-

lyr1.zIndex = 9;
lyr2.z = 8;
a.style.zIndex = 11;
};
</script>

<snip>


Thank you, I realized , about 2 hours after posting, that you can't make an
object pointer to a property that contains a value, that the pointer will
be used as a variable, instead.

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.