9 Replies Latest reply on Apr 24, 2006 7:35 AM by halcyon32

    Internal XML problems AS2.0

    halcyon32 Level 1
      Hi all
      I could use a little help internalizing an XML file... I have found some examples of how to do this but they all seem to be for AS1.0 and they don't work in AS2.0 or at least not in my AS2.0

      So I have started here with your typical loading of an external XML file.

      I hope this makes sense... If not let me know and I will try to clear it up...

      Thanks in advance
        • 1. Re: Internal XML problems AS2.0
          blemmo Level 1

          there are various issues in that codes: the XML class has no trigger(), the line
          this.timelineXML.onload = processXML ()
          is totally wrong (in the context of the posted code). But this shouldn't affect the loading, so the problem should be
          eval ("entry_clip" + i).entry_text.text = timeLineXMLConn;
          eval() shouldn't be used this way, so better use dot or array syntax here:
          _root[ "entry_clip"+i ].entry_text.text
          Make sure the path is right and that 'i' is defined. Also don't do
          (...).text = timeLineXMLConn;
          but rather
          (...).text = timeLineXMLConn.toString().
          This is the whole loading code:
          var timeLineXMLConn:XML = new XML();
          this.timeLineXMLConn.ignoreWhite = true;
          trace("this is = "+this);
          this.timeLineXMLConn.onLoad = function(success:Boolean):Void {
          if (success) {
          //trace("this is Loaded = "+this);
          _root["entry_clip"+i].entry_text.text = this.toString();
          } else {
          trace("error loading XML file");

          For the xml creating: the parameter for the XML constructor is a string surrounded by " ", but it contains also string signs ("), so you have to decide which sort (simple ' or double ") defines which strings: if the xml string is surrounded by " ", you can use ' ' inside it, or you use the other way around (it doesn't matter which way you use, it just has to be clear). E.g.:
          var xml = new XML ( "<?xml version='1.0' encoding='iso-8859-1' ?><root><entry id='entry1' /></root>" );
          To mask the signs, when you want to use the same sort inside the string as surrounding, use a backslash before it, so it won't get interpreted as end of the string:
          var xml = new XML ( "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?> ..." );

          But if you want to test your code using this string, you shouldn't call load() after you created the xml, it will replace the just created content.

          • 2. Re: Internal XML problems AS2.0
            halcyon32 Level 1
            Ok well I have traced the problem down to the

            this.timeLineXMLConn.onLoad = function (success:Boolean):Void { }

            When I trace ("timeLineXMLConn = " + timeLineXMLConn); out side of the onLoad function it shows an output. But when I do the same trace ("timeLineXMLConn = " + timeLineXMLConn); inside of my timeLineXMLConn.onLoad = function I get nothing....

            I don't think this: this.timeLineXMLConn.onLoad = function (success:Boolean):Void is getting called...
            it might be something to do with the way the var timeLineXMLConn:XML = new XML (); is being triggered this.timeLineXMLConn.trigger ();

            • 3. Re: Internal XML problems AS2.0
              blemmo Level 1
              onLoad can't get called now, because you don't use XML.load(). Delete the trigger action; the XML class has no trigger function. A call to XML.load() starts loading, which triggers the onLoad event when it's finished. Inside onLoad, you can use "this" to reference to the XML object:
              trace("the xml = "+this);

              • 4. Re: Internal XML problems AS2.0
                halcyon32 Level 1
                Hi blemmo,
                Thanks for the reply,

                I'm posting the entire code... I'm no longer useing the eval ("entry_clip" + i) chunk of code. Im now useing this["plot" + h + "" + i].

                I think this.timeLineXMLConn.onLoad = function (success:Boolean):Void is not being called or the this.timeLineXMLConn.trigger (); is workingt right....

                when I trace ("timeLineXMLConn = " + timeLineXMLConn); in side the onLoad function() { I get nothing. But if I trace ("timeLineXMLConn = " + timeLineXMLConn); outside the onLoad function() { I get my XML back....

                Take a look...


                • 5. Re: Internal XML problems AS2.0
                  blemmo Level 1
                  Please read more carefully, I now write it for the 3rd time: there is no XML.trigger() function. Calling this won't do anything. Hit F1 inside Flash and look up the XML class and its methods, you won't find "trigger()". While you're there, check the entry for XML.load().

                  If you want to call "processXML" when the loading finished successfully, just call it inside onLoad:
                  this.timeLineXMLConn.onLoad = function (success:Boolean):Void {
                  if (success) {
                  trace("this is Loaded = "+this);
                  trace ("timeLineXMLConn = " + timeLineXMLConn);
                  processXML ();
                  } else {
                  trace ("error loading XML file");

                  onLoad can only be executed when load() was called. To test processXML with the xml string created in Flash, just call processXML() after the XML object was created (and don't call load() in between).
                  • 6. Re: Internal XML problems AS2.0
                    halcyon32 Level 1
                    Ok.... So All I need to do is:

                    var timeLineXMLConn:XML = new XML ("<XML HERE>");
                    this.timeLineXMLConn.ignoreWhite = true;
                    processXML ();

                    Or am I a complete dumb @!#$

                    by the way if I haven't said it yet. thanks for taking the time to explain this to me...
                    • 7. Re: Internal XML problems AS2.0
                      blemmo Level 1
                      you're welcome, de nada.

                      yes, the 3 lines are all you need for testing processXML. Pay some attention on the scope of 'this', it may be unclear where "var timeLineXMLConn" gets attached to, it depends on where the code is placed and from which context it is called. It's safer to not use it here, and just reference timeLineXMLConn without it.
                      It's also safer to pass the xml reference into the process function, instead of writing the reference into the function. That way the function is far more flexible, just depending on the input.

                      var timeLineXMLConn:XML = new XML ("<XML HERE>");
                      timeLineXMLConn.ignoreWhite = true;
                      processXML (timeLineXMLConn);

                      /************* Process XML *****************/
                      function processXML ( xml:XML) {
                      trace ("processXML = " + "Called");
                      // the y value of our entries,
                      // ie how far above the line they are
                      root_element = xml.firstChild;

                      • 8. Re: Internal XML problems AS2.0
                        Peter Lorent Level 2
                        >>they all seem to be for AS1.0 and they don't work in AS2.0
                        That's because that code is supposed to be used with a XMLConnector component...
                        • 9. Re: Internal XML problems AS2.0
                          halcyon32 Level 1
                          Hey guys thanks,

                          I'll be sure to call my function as such:
                          processXML (timeLineXMLConn);

                          function processXML (xml:XML) { }

                          I also just learned I should look into using Xpath instead of XMLConnector class. So i guess I will be doing some studying on Xpath...

                          Once again thanks for all your help..