Connecting Tech Pros Worldwide Forums | Help | Site Map

Object Pointers

Ralph??
Guest
 
Posts: n/a
#1: Jul 20 '05
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



Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Object Pointers


"Ralph??" <ravensha@stis.net> writes:
[color=blue]
> 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.[/color]
....[color=blue]
> 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.[/color]

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.
[color=blue]
> How do I rectify this?[/color]

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

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Richard Cornford
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Object Pointers


"Ralph??" <ravensha@stis.net> wrote in message
news:ba898ae9636e5c4ecbc0ecac61121af3@free.teranew s.com...[color=blue]
>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.[/color]
[color=blue]
> Script Example:
> <script>
> var lyr1, lyr2;[/color]

That will correctly define the two global variables.
[color=blue]
> function initIE(){
> lyr1 = layer1.style;[/color]

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.
[color=blue]
> lyr2 = layer2.style;
> lyr1.z = lyr1.zIndex;[/color]

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.
[color=blue]
> lyr2.z = lyr2.zIndex;
> };
>
> function switcher(a){
> lyr1.z = 9;[/color]

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;
[color=blue]
> lyr2.z = 8;
> a.style.zIndex = 11;
> };
> </script>[/color]
<snip>


Ralph??
Guest
 
Posts: n/a
#4: Jul 20 '05

re: Object Pointers



"Lasse Reichstein Nielsen" <lrn@hotpop.com> wrote in message
news:n0ft3dvs.fsf@hotpop.com...[color=blue]
> "Ralph??" <ravensha@stis.net> writes:
>[/color]
[color=blue]
> Forget the "z" property and change the two first lines of switcher to
> lyr1.zIndex = 9;
> lyt2.zIndex = 8;
>[/color]

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.



Ralph??
Guest
 
Posts: n/a
#5: Jul 20 '05

re: Object Pointers



"Richard Cornford" <Richard@litotes.demon.co.uk> wrote in message
news:be5e5a$opa$1$8302bc10@news.demon.co.uk...[color=blue]
> "Ralph??" <ravensha@stis.net> wrote in message
> news:ba898ae9636e5c4ecbc0ecac61121af3@free.teranew s.com...[color=green]
> >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.[/color]
>[color=green]
> > Script Example:
> > <script>
> > var lyr1, lyr2;[/color]
>
> That will correctly define the two global variables.
>[color=green]
> > function initIE(){
> > lyr1 = layer1.style;[/color]
>
> 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.
>[color=green]
> > lyr2 = layer2.style;
> > lyr1.z = lyr1.zIndex;[/color]
>
> 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.
>[color=green]
> > lyr2.z = lyr2.zIndex;
> > };
> >
> > function switcher(a){
> > lyr1.z = 9;[/color]
>
> 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;
>[color=green]
> > lyr2.z = 8;
> > a.style.zIndex = 11;
> > };
> > </script>[/color]
> <snip>
>
>[/color]

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.



Closed Thread