3 Replies Latest reply on Jan 24, 2007 6:17 AM by Peter Lorent

    I need help in XML

    mousa1982
      hi there,
      i start using flash actionscript couple a day and i write some code and its work but when i start to use class's and oop the code not work any one can help me this is my class:

      import mx.controls.Label;
      import mx.controls.*;
      import mx.utils.Delegate;

      //import mx.controls.MovieClip;
      /**
      * The Ball class extends the dynamic MovieClip class and and is therefore also
      * dynamic. The Ball class assumes a MovieClip in the library is assoicated with
      * this class. The Ball class provides the associated movie clip with the three
      * predetermined behaviors:
      * 1. The clip will appear in a random position on the stage.
      * 2. The clip will move in a random direction with a random velocity.
      * 3. The clip will bounce off the edges of the stage in order to remain
      * entirely within the stage.
      * Version: 2
      * Author: Brian Lesser
      */
      dynamic class Nodee extends MovieClip
      {
      // Variable set in attachMovie and used by the text field.
      var ln:Number = 0;
      var PersonalXml:XML;
      var Obj:Object;
      //private var theScope:MovieClip;
      //XML Node That will Read from it
      public var fileName:String;
      var myData:Array = new Array();
      var myField:Array = new Array();
      var theScope:MovieClip;
      /**
      * The Ball constructor function calculates the bounding rectangle
      * within which this clip's registration point is allowed to travel.
      * The clip's registration point is assumed to be in the center of the
      * clip but the height and width of the clip do not have to be the same.
      * Therefore the bounding rectangle is calculated for each clip when
      * each clip's constructor is called.
      * The Stage object provides Stage.width and Stage.height.
      * A random starting position and random velocity are also determined.
      */
      function Nodee()
      {
      // Calculate the limits of travel for this clip's registration point.
      //fileName=file;
      //trace(file);
      theScope=new MovieClip();
      theScope = createEmptyMovieClip("theScope", getNextHighestDepth());
      // Determine the random starting position within the Stage for this clip.
      _x = 10;
      _y = 10;
      _width = 200;
      _height = 200;
      trace("loadMove");
      PersonalXml = new XML();
      PersonalXml.ignoreWhite = true;
      PersonalXml.onLoad = loadData;
      PersonalXml.load(" http://localHost/foe/FriendsWord.xml");
      Obj=new Object();
      }
      /**
      * The onEnterFrame method calculates the next postion for the movie clip
      * and then checks to make sure it is within the movie clip's travel limits.
      * If it is not the position of registration point is recalculated as though
      * it has just bounced off the edge of the stage. The x and y position of the
      * registration point are calculated separately.
      */
      function onLoad()
      {
      //selectedCat = evtObj.target.selectedItem.label;
      //trace(fileName);
      //+ fileName);
      //trace(PersonalXml);
      //loadData();
      }

      function loadData(success:Boolean):Void
      {
      if (success)
      {
      var RootNodetmp:XMLNode;
      RootNodetmp = this.firstChild;
      trace(RootNodetmp.firstChild);
      trace("");
      trace(RootNodetmp.childNodes[0].childNodes.length);
      var k:Number = RootNodetmp.childNodes[0].childNodes.length + 50;
      for (var i:Number = 0; i < RootNodetmp.childNodes[0].childNodes.length; i++)
      {
      trace(RootNodetmp.childNodes[0].childNodes .attributes.type);
      switch (RootNodetmp.childNodes[0].childNodes
      .attributes.type)
      {
      case "Label" :
      Obj = theScope.createClassObject(mx.controls.Label, "pp" + i, theScope.getNextHighestDepth() + 1, {text:"sss", _x:200, _y:60 + (25 * i)});
      trace(["pp"+i].text);
      break;
      case "TextInput" :
      Obj = theScope.createClassObject(mx.controls.TextInput, "pp" + i, theScope.getNextHighestDepth() + 1, {text:"nnn", _x:200, _y:60 + (25 * i)});
      trace(["pp"+i].text);
      break;
      default :
      Obj = theScope.createClassObject(mx.controls.TextInput, "pp" + i, theScope.getNextHighestDepth() + 1, {text:"mm", _x:200, _y:60 + (25 * i)});
      trace(["pp"+i].text);
      break;
      }

      myData ._width = RootNodetmp.childNodes[0].childNodes.attributes.w;
      myData ._height = RootNodetmp.childNodes[0].childNodes.attributes.h;
      myData .Color.rgb = (RootNodetmp.childNodes[0].childNodes.attributes.color);
      var l:Label = (theScope.createClassObject(mx.controls.Label, "Label" + i, theScope.getNextHighestDepth() + 2, {text:CorrectName(RootNodetmp.childNodes .nodeName), _x:50, _y:60 + (25 * i)}));
      trace(l);
      myField
      = l;
      myField .autoSize = true;
      k = k + 1;
      }
      ln = RootNodetmp.childNodes[0].childNodes.length;
      //this.attachMovie("Node","node1",1);
      }
      else
      {
      status.text = ("Error in loading XML file");
      }
      }
      public function CreateGUI(NodeValue:XML):Void
      {
      var RootNodetmp:XMLNode;
      RootNodetmp = NodeValue.firstChild;
      trace(NodeValue.firstChild);
      trace("");
      trace(RootNodetmp.childNodes.length);
      var k:Number = RootNodetmp.childNodes.length + 50;
      for (var i:Number = 0; i < RootNodetmp.childNodes.length; i++)
      {
      trace(RootNodetmp.childNodes
      .attributes.type);
      switch (RootNodetmp.childNodes .attributes.type)
      {
      case "Label" :
      var mn:Label = (_root.theScope.createClassObject(mx.controls.Label, "pp" + i, getNextHighestDepth() + 1, {text:"", _x:200, _y:60 + (25 * i)}));
      break;
      case "TextInput" :
      var mn:TextInput = (_root.theScope.createClassObject(mx.controls.TextInput, "pp" + i, getNextHighestDepth() + 1, {text:"", _x:200, _y:60 + (25 * i)}));
      break;
      default :
      var mn:TextInput = _root.theScope.createClassObject(mx.controls.TextInput, "pp" + i, getNextHighestDepth() + 1, {text:"mm", _x:200, _y:60 + (25 * i)});
      break;
      }
      trace(mn);
      myData
      ._width = RootNodetmp.childNodes[0].childNodes .attributes.w;
      myData
      ._height = RootNodetmp.childNodes[0].childNodes .attributes.h;
      myData
      .Color.rgb = (RootNodetmp.childNodes[0].childNodes .attributes.color);
      var l:Label = (theScope.createClassObject(mx.controls.Label, "Label" + i, getNextHighestDepth() + 2, {text:CorrectName(RootNodetmp.childNodes
      .nodeName), _x:50, _y:60 + (25 * i)}));
      trace(l);
      myField = l;
      myField
      .autoSize = true;
      k = k + 1;
      }
      ln = RootNodetmp.childNodes[0].childNodes.length;
      }
      function CorrectName(myString:String):String
      {
      var newStr:String = '';
      var strArray:Array;
      var Startindex:Number = 0;
      strArray = myString.split('_', 1000);
      var Changed:Boolean = false;
      for (var i = 0; i < myString.length; i++)
      {
      //trace(myString.substring(i,i+1));
      if (myString.substring(i, i + 1) == "_")
      {
      //trace("in");
      newStr += myString.substring(Startindex, i) + " ";
      Startindex = i + 1;
      Changed = true;
      }
      }
      return newStr + myString.substring(Startindex, myString.length);
      }
      }

      this is the xML file FriendsWord.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <FriendsWord>
      <data id="0">
      <Friend_Name type= "Label" w="300" h="20" color="0xffffff" >1234</Friend_Name>
      <Email type= "TextInput" w="300" h="20" color="#828282" format="*@*.*">IE</Email>
      <Comments>PC</Comments>
      <Telephone_or_Mobile>dddd</Telephone_or_Mobile>
      <Date>2-1-2006</Date>
      </data>
      </FriendsWord>


      the problem is when i make new class object in this statment:


      Obj = theScope.createClassObject(mx.controls.Label, "pp" + i, theScope.getNextHighestDepth() + 1, {text:"sss", _x:200, _y:60 + (25 * i)});
      trace(["pp"+i].text);
      break;

      the trace return null or undifined.
      please help me