Object Pointers

R

Ralph??

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
 
L

Lasse Reichstein Nielsen

Ralph?? said:
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
 
R

Richard Cornford

Ralph?? said:
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>
 
R

Ralph??

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.
 
R

Ralph??

Richard Cornford said:
That will correctly define the two global variables.


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.


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.


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;

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

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top