3 Replies Latest reply on Nov 10, 2006 12:32 PM by JeffreyGong

    Flax, XML and E4X Parsing...

    mirzahat
      Hello,
      I have this code from a tutorial

      import flash.net.URLLoader
      import flash.net.URLRequest
      import flash.net.URLLoader
      import flash.net.URLRequest
      import flash.xml.XML
      import flash.event.*
      import flash.error.*

      var mainXML:XML;
      var loader:URLLoader = new URLLoader();
      loader.addEventListener(Event.COMPLETE, onComplete);
      loader.load(new URLRequest(' http://www.sephiroth.it/tutorials/flashPHP/E4X/files/test.xml'));

      function onComplete(evt:Event)
      {
      mainXML = new XML(loader.data)
      trace("xml loaded, start parsing using E4X syntax");
      }

      The Code loads an external XML file. But when I place this code into my Flash Builder IDE I got message that the packages:

      import flash.xml.XML;
      import flash.event.*;
      import flash.error.*;

      are not available. The I also get the message from the IDE, that the "loader" and "onComplete" porperty are not defined.

      I really don't know why because it really seems that the code is ok...

      Regards,
      Mirza
        • 1. Re: Flax, XML and E4X Parsing...
          ntsiii Level 3
          Looks like a problem with the example, maybe it was from a beta? Or even 1.5.

          According to the FlexBuilder auto-complete, those packages do not exist.

          The reason for the other two errors is that you can't do those complex assignments outside of a function. Put them in an initApp() function called by the creationComplete event and they will go away.

          Only declarations and assignments to simple types can be done outside a function.

          Tracy
          • 2. Re: Flax, XML and E4X Parsing...
            ntsiii Level 3
            Ok, definitely not 1.5 ;)

            Where is that example? It has caused a lot of trouble.
            • 3. Re: Flax, XML and E4X Parsing...
              JeffreyGong Level 1
              Hi mirzahat,

              Where did you run your script?

              How about to put your script inside a method of an application like

              =============================================================
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" initialize="init()">
              <mx:Script>
              <![CDATA[

              private var mainXML:XML;
              private var loader:URLLoader;

              private function init():void {
              loader = new URLLoader();
              loader.addEventListener(Event.COMPLETE, onComplete);
              loader.load(new URLRequest(' http://www.sephiroth.it/tutorials/flashPHP/E4X/files/test.xml'));
              }

              private function onComplete(evt:Event):void {
              mainXML = new XML(loader.data)
              out.text += "xml loaded, start parsing using E4X syntax\n";
              out.text += mainXML+""
              }

              ]]>
              </mx:Script>

              <mx:TextArea id="out" width="400" height="300"/>

              </mx:Application>
              ===============================================

              It should work. And you don't have to import those packages.

              Have fun!

              Jeffrey