3 Replies Latest reply on Apr 10, 2011 1:38 PM by Ned Murphy

    Can't add mc

    NancyJanetKing Level 1

      Hi;

      I have this code:

       

              private function completeHandler(event:Event):void
              {
                  var loader:URLLoader=URLLoader(event.target);
                  var result:XML=new XML(loader.data);
                  var myXML:XMLDocument=new XMLDocument();
                  myXML.ignoreWhite=true;
                  myXML.parseXML(result.toXMLString());
                  var node:XMLNode=myXML.firstChild;
                  var n:int=int(node.childNodes.length);
                  for(var i:int=0;i<n;i++)
                  {
                      var mc:MovieClip=new MovieClip();
                      mc.image=node.childNodes[i].attributes['source'];
                      mc.x = 0+i*100;
                      mc.y = 200;
                      addChild(mc);
                  }

       

      Everything seems to work except that the mc never appears on the screen. I can trace out the mc and its x and y values and they all trace out as expected. The images get loaded and no error is thrown. The complete code follows.

       


      Thanks,,

      Nancy

       

       

      package  {
          import com.greensock.*;
          import flash.display.MovieClip;
          import flash.display.Sprite;
          import flash.events.Event;
          import flash.events.MouseEvent;
          import flash.display.Loader;
          import flash.events.Event;
          import flash.net.URLLoader;
          import flash.net.URLRequest;
          import flash.xml.*;
          import flash.geom.ColorTransform;
         
          public class InfiniteScroll extends MovieClip {
              private var mc1:MovieClip = new MovieClip();
              private var mc2:MovieClip = new MovieClip();
              private var mc3:MovieClip = new MovieClip();
              private var mc4:MovieClip = new MovieClip();
              private var mcArray:Array = new Array(mc1, mc2, mc3, mc4);

       

              public function InfiniteScroll()
              {
                  loadXML();
              }
             
              private function loadXML():void
              {
                  var loader:URLLoader=new URLLoader();
                  loader.addEventListener(Event.COMPLETE,completeHandler);
                  var request:URLRequest=new URLRequest("loadImages.xml");
                  try
                  {
                      loader.load(request);
                  }
                  catch(error:Error)
                  {
                      trace("Cannot load the xml document.");
                  }
              }
             
              private function completeHandler(event:Event):void
              {
                  var loader:URLLoader=URLLoader(event.target);
                  var result:XML=new XML(loader.data);
                  var myXML:XMLDocument=new XMLDocument();
                  myXML.ignoreWhite=true;
                  myXML.parseXML(result.toXMLString());
                  var node:XMLNode=myXML.firstChild;
                  var n:int=int(node.childNodes.length);
                  for(var i:int=0;i<n;i++)
                  {
                      var mc:MovieClip=new MovieClip();
                      mc.image=node.childNodes[i].attributes['source'];
                      mc.x = 0+i*100;
                      mc.y = 200;
                      addChild(mc);
                  }
              }
             
              function scrollIt(mc:MovieClip)
              {
                  TweenMax.to(mc, 2, {x:mc.x + 100, onComplete:function () {if (mc.x>300){mc.x=0}TweenLite.delayedCall(1,scrollIt(mc))}});
              }
          }
      }