Loading ...
Sorry, an error occurred while loading the content.

javascript structure & cleaning the canvas

Expand Messages
  • bradthetaylor
    I have a two part question. 1. How do i clean the canvas 2. What do i need to cleanup in javascript when re-painting A brief description of what I am doing,
    Message 1 of 2 , Oct 1, 2004
    • 0 Attachment
      I have a two part question.
      1. How do i "clean" the canvas
      2. What do i need to cleanup in javascript when re-painting

      A brief description of what I am doing, should make the questions
      more intelligible.

      I have an html page that contains an XML SVG document, that embeds a
      script file that uses the onload function.

      The script files onload function issues a postURL to request an XML
      document from my server.

      The script, upon receipt of the XML document uses parseXML, runs
      thru the elements and creates various an sundry svg elements.

      One of the svg elements is a button that requests a new document
      from the server. When that button is pressed, I want to logically
      start all over again.

      Currently the old "picture" stays on the browser, question 1 above.

      The javascript that parses the xml document creates lots of
      javascript objects. I am concerned about consuming resources, if I
      dont clean them up.

      And finally I am concerned about the architecture of the
      javascript. The original javascript gets invoked from the onload
      function code snippit as follows:

      function init(evt) {
      postURL('getxml', "",processXML, 'text/xml', null);
      }
      function processXML(xmldoc) {
      var node = new picture(xmlDoc);
      }

      The picture function is the one that parses the xml and invokes
      other functions. These functions implement one of the OOP models,
      thus I think of them as Objects.

      One of the last things the picture function does is:
      var but = new button(.....)
      but.setEventListener('click',this,'butpressed');
      return;
      }


      picture.prototype.butpressed = function(e) {
      var t = SVGGroup.getFirstChild();
      if (t != null)
      SVGGroup.removeChild(t);
      postURL('getxml', "",processXML, 'text/xml', null);
      }

      Thus when the button is pressed, I want to start over. But since I
      am running in an event handler, are there implications.

      Thanx
      Brad Taylor
      Western Metal Supply
    • Jim Ley
      bradthetaylor wrote in message news:cjk24v+8rrt@eGroups.com... ... Just delete all the childnodes from the root Element.
      Message 2 of 2 , Oct 1, 2004
      • 0 Attachment
        "bradthetaylor" <btaylor@...> wrote in message
        news:cjk24v+8rrt@......
        >
        > I have a two part question.
        > 1. How do i "clean" the canvas

        Just delete all the childnodes from the root Element.

        > 2. What do i need to cleanup in javascript when re-painting

        just make sure you've got no references to the old DOM objects laying about,
        especially circular ones.
        see:
        http://jibbering.com/faq/faq_notes/closures.html#clMem

        for a common problem.

        > The picture function is the one that parses the xml and invokes
        > other functions. These functions implement one of the OOP models,
        > thus I think of them as Objects.

        well it's javascript, so everything's an Object :-)

        > One of the last things the picture function does is:
        > var but = new button(.....)
        > but.setEventListener('click',this,'butpressed');

        I'd definately remove the event listener before anything else.

        > var t = SVGGroup.getFirstChild();

        Use .firstChild - not .getFirstChild()

        > Thus when the button is pressed, I want to start over. But since I
        > am running in an event handler, are there implications.

        There shouldn't be.

        Cheers,

        Jim.
      Your message has been successfully submitted and would be delivered to recipients shortly.