Thats because you must wait for the page to load before creating
layers.  You should use DynAPI.onLoad = function() {} and put your
code in there.  DynAPI.document is not created until the page is
finished loading, thats why you are getting that error.  Or you can also
check for DynAPI.loaded in the function makeLayer:

function MakeLayer(){
 if(!DynAPI.loaded) return;
 layer=new DynLayer(null,Math.random()*400,Math.random()*400,50,50,'#c0c0c0')
 DynAPI.document.addChild(layer)
}
-- 
// Robert Rainwater

On 2/24/2001, 3:11:30 PM EST, Derf wrote about "[Dynapi-Help] I do not get it...":


> people 
> can someone help me plz?

> <html>
> <head><title>Deleting layers</title>

> <script language="Javascript" src="dynapi/src/dynapi.js"></script>

> <script language="Javascript">

> DynAPI.setLibraryPath('dynapi/src/lib/')

> DynAPI.include('dynapi.api.browser.js')
> DynAPI.include('dynapi.api.dynlayer.js')
> DynAPI.include('dynapi.api.dyndocument.js')

> function MakeLayer(){
>  layer=new DynLayer(null,Math.random()*400,Math.random()*400,50,50,'#c0c0c0')
>  DynAPI.document.addChild(layer)
> }

> function DeleteLayer(){
>  if (DynAPI.document.children.length>0) {
>   var index=DynAPI.document.children.length-1
>   DynAPI.document.children[index].deleteFromParent()
>  } else alert('all layers are removed')
> }


> </script>
> </head>


> --------------- option 1
> <body>
> <a href="javascript:MakeLayer()">Make layer</a><br>
> <a href="javascript:DeleteLayer()">Delete layer</a>

> </body>
> </html>

> --------------- option 2
> <script language="Javascript">
> MakeLayer()
> </script>


> option 1 works, option 2 doesn't
> Why?  he doesn 't find DynAPI.document (it is false)

> Why is this in option 2 like that and not in option 1 ?

> I would be thankfull for a solution 

> Greetingz 
> Derf


----------------------
DynAPI Snapshots: http://dynapi.sourceforge.net/snapshot/
DynAPI Homepage: http://dynapi.sourceforge.net/



_______________________________________________
Dynapi-Help mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-help

Reply via email to