[haXe] [js] being sure all is loaded before proecessing
Franco Ponticelli
franco.ponticelli at gmail.com
Mon Apr 3 19:45:39 CEST 2006
Actually when you include you js (haxe generated), the main method is called
on the end of the js parsing.
This may create problems if your script pretends to manipulate the DOM of
the page.
To get around this I do the following:
<code>
class MainClass
{
static public function main() : Void
{
if(js.Lib.document.body == null)
js.Lib.window.onload = onload;
else
onload(null);
}
static public function onload(evt : Event) : Void
{
js.Lib.alert("hello");
}
}
</code>
All my code goes in onload.
Pay attention that I have had to add the event onload in the Window class
(which is legal).
This way you can include the js in the head instead of directly in the body
...
Hope someone will find this useful :-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.motion-twin.com/pipermail/haxe/attachments/20060403/b2eaefc8/attachment.htm
More information about the Haxe
mailing list