It seems to me this whole adventure is based on your desire to know "where"
the DynAPI placed you button object in the chiild array (just a guess :O) ).
This is probably caused by the default and oft not well explained habit of
the API and all of its said examples using the defauly ID setting. You can
override this.
MyButton = new DynLayer("Pascalizier",125,125,12,12)
This can make finding the little bugger allot easier then wondering where it
was randomly assigned during object creation (which creates the great
"mystery" ID).
Cheers,
Ray
PS this particular button triggers a "throw a large boulder" event on the
U.S.S Rock. If this makes no sense to you your new and I've been up to long
again. :O)
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Jordi
Ministral
Sent: Thursday, May 31, 2001 2:05 PM
To: [EMAIL PROTECTED]
Subject: Re: [Dynapi-Help] An Array of DynLayers
That's a very educative event example, I must say.
You are creating a 'i' variable and using it in a loop. Each layer is given
a
mouseup listener that goes
alert("I am "+i)
but when is this executing ? Not now. The method you are setting is one that
will execute onmouse up, and then 'i' will be 2, because mouseups happen
after
your initialization loop. Try this one:
Events[i].onmouseup = new Function( "alert(' I am "+i+"')" )
See now each method contains a different string, because the string is
constructed on function creation, and we are not using a variable that was
set
before, as it was in your example.
"GARRIS, TRAVIS" wrote:
> I hope I'm not flooding the list on my first day, but I gots to axe
> questions.
>
> Why do I get the result "I am 2" when I click on of the buttons in the
> example below?
>
> I created myText to see if I could affect objects via the array. I can.
>
> I created Button0 and Button1 to put into an array, and try to generate
> their events in a for loop. Button0 should change myText to "I am 0", and
> Button1 should change myText to "I am 1". Both of them change myText to
"I
> am 2". Why?
>
> ---
> <html>
>
> <head>
>
> <script language='JavaScript'
> src='/JavaScripts/dynapi/src/dynapi.js'></script>
>
> <script lanugage='JavaScript'>
> DynAPI.setLibraryPath('/JavaScripts/dynapi/src/lib/');
> DynAPI.include('dynapi.api.*');
> DynAPI.include('dynapi.event.*');
> DynAPI.include('dynapi.ext.inline.js');
> DynAPI.include('dynapi.util.debug');
> </script>
>
> <script language='JavaScript'>
>
> DynAPI.onLoad = function(){
>
> var myText = this.document.getAll()["myText"]
> myText.setVisible(true);
> var myEvent = new EventListener(this.document);
> myEvent.onmouseup = function() {
> Buttons[0].setHTML("Touch 0");
> Buttons[1].setHTML("Touch 1");
> };
> myText.addEventListener(myEvent);
>
> var Buttons = new Array;
> var Events = new Array;
>
> for(var i = 0; i < 2; i++) {
>
> Buttons[i] = this.document.getAll()["Button" + i]
> Buttons[i].setVisible(true);
> Events[i] = new EventListener(this.document);
> Events[i].onmouseup = function() {
> myText.setHTML("I am " + i);
> };
> Buttons[i].addEventListener(Events[i]);
>
> }
>
> };
>
> </script>
>
> </head>
>
> <body>
>
> <div id='myText' style='position:relative;
> visibility:hidden;'>Yeap</div>
>
> <div id='Button0' style='position:relative; visibility:hidden;'>Button
> 0</div>
>
> <div id='Button1' style='position:relative; visibility:hidden;'>Button
> 1</div>
>
> </body>
>
> </html>
> ----
>
> Travis Garris, Ciber
> Winston-Salem, NC
>
> _______________________________________________
> Dynapi-Help mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/dynapi-help
_______________________________________________
Dynapi-Help mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-help
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.255 / Virus Database: 128 - Release Date: 5/17/2001
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.255 / Virus Database: 128 - Release Date: 5/17/2001
_______________________________________________
Dynapi-Help mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-help