25 Replies Latest reply on Feb 21, 2011 12:35 PM by beno12345

    removeChild/addChild Problem

    beno12345 Level 1

      Hi;

      I have this code:

       

              public function Slides(_numOfSlides:int, _totalSlides:int, _w:int, _h:int, _x:int, _y:int):void
              {
                  if (parent_container.parent)
                  {
                      parent_container.parent.removeChild(parent_container);
                  }
                  addChild(parent_container);
                  var container:MovieClip = new MovieClip();
                  spacer = 10;
                  AddSlides();
                  timeline = new TimelineMax({onComplete:NextSlide()});
                  timeline.append(TweenLite.to(parent_container, 0, {x:150}) );
              }

       

      It works well, except that it "blinks" between the removeChild(parent_container) and the addChild(parent_container). That is, there is a moment where nothing is visible. Now, I guess I could build two of these parent containers, one behind the other, and then wipe out one and build a new one behind the other, and thus give the optical illusion that nothing is amiss; however, that doesn't strike me as terribly elegant. Is there a better solution?

      TIA,

      Beno

        • 1. Re: removeChild/addChild Problem
          kglad Adobe Community Professional & MVP

          something else must be causing that.  in addition, there's no need to execute that removeChild() method.  an object can only have one parent so flash will remove the child when you execute the addChild() method.

          • 2. Re: removeChild/addChild Problem
            Ned Murphy Adobe Community Professional & MVP

            I would doubt that there is any visually detectable gap between the remove and add executions.  It is more likely something to do with whatever is being added into the parent_container object

            • 3. Re: removeChild/addChild Problem
              beno12345 Level 1

              Well, Ned, I have this exact same problem with another site. I remember going through this on the chatty.figleaf discussion list (until they booted me off because they didn't like my questions) and we never got it resolved, despite a lot of participation. If you make your own images and Slides.fla you can see for yourself what it does. I call it from another *.fla with this:

               

                          var mySlides:Slides = new Slides(_numOfSlides, _totalImages, _w, _h, _x, _y);

               

              but you could easily edit it to run it directly. Here's the code, down trimmed a bit as best I could:

               

              package  {
                  import com.greensock.*;
                  import flash.display.MovieClip;
                  import flash.events.TimerEvent;
                  import flash.utils.Timer;
                  import flash.net.URLRequest;
                  import flash.net.URLLoader;
                  import flash.display.Loader;
                  import flash.display.LoaderInfo;
                  import flash.events.Event;
                  import Images;
                 
                  [SWF(backgroundColor="0x000000", width="1008", height="548")]
                 
                  public class Slides extends MovieClip
                  {
                      var parent_container:MovieClip = new MovieClip();
                      var imagesArray:Array = new Array("images/1.png",
                                                         "images/2.png",
                                                         "images/3.png",
                                                         "images/4.png",
                                                         "images/5.png",
                                                         "images/6.png",
                                                         "images/7.png",
                                                         "images/8.png",
                                                         "images/9.png",
                                                         "images/10.png",
                                                         "images/11.png",
                                                         "images/12.png");
                      var _totalSlides:Number = new Number(12);
                      var _numOfSlides:Number = new Number(6);
                      var _totalImages:Number = new Number(12);
                      var _w:Number = new Number(120);
                      var _h:Number = new Number(120);
                      var _x:Number = new Number(213);
                      var _y:Number = new Number(150);
                      var img:Images;
                      var img0:Images;
                      var img1:Images;
                      var img2:Images;
                      var img3:Images;
                      var img4:Images;
                      var img5:Images;
                      var i:int;
                      var spacer:int;
                      var j:int;
                      var _firstImageInArray:int;
                      var _secondImageInArray:int;
                      var _thirdImageInArray:int;
                      var _fourthImageInArray:int;
                      var _fifthImageInArray:int;
                      var _sixthImageInArray:int;
                      var _const:int;
                      var _const_mod:int;
                      var k:int = 0;
                      var _mod:int;
                      var ImageDisplayArray:Array;
                      var timeline:TimelineMax;
                      var myTimer:Timer = new Timer(1000);
                      var iterations:int=0;
                      var urlXMLLoader:URLLoader;
                      var shoppingCartImagesArray:Array = new Array();
                      var shoppingCartURLArray:Array = new Array();
                      var imageDir:String = new String();
                     
                      public function Slides(_numOfSlides:int, _totalSlides:int, _w:int, _h:int, _x:int, _y:int):void
                      {
                          addChild(parent_container);
                          var container:MovieClip = new MovieClip();
                          spacer = 10;
                          AddSlides();
                          timeline = new TimelineMax({onComplete:NextSlide()});
                          timeline.append(TweenLite.to(parent_container, 0, {x:150}) );
                      }
                     
                      function AddSlides():void
                      {
                          _const = (Math.round((iterations+_numOfSlides/2)/_numOfSlides));
                          _const_mod = _const*_numOfSlides%imagesArray.length;
                          if (_const_mod == _numOfSlides)
                          {
                              _const = 1;
                          } else {
                              _const = 0;
                          }
                          LoadImageDisplayArray();
                      }

               

                      function LoadImageDisplayArray():void
                      {
                          ImageDisplayArray = null;
                          ImageDisplayArray = new Array();
                          _mod = iterations%_numOfSlides;
                          if (iterations == _numOfSlides)
                          {
                              _firstImageInArray = _const*_numOfSlides+_mod;
                              _secondImageInArray = _const*_numOfSlides+_mod+1;
                              _thirdImageInArray = _const*_numOfSlides+_mod+2;
                              _fourthImageInArray = _const*_numOfSlides+_mod+3;
                              _fifthImageInArray = _const*_numOfSlides+_mod+4;
                              _sixthImageInArray = _const*_numOfSlides+_mod+5;
                              iterations = -1;
                          } else {
                              _firstImageInArray = _const*_numOfSlides+_mod-6;
                              _secondImageInArray = _const*_numOfSlides+_mod-5;
                              _thirdImageInArray = _const*_numOfSlides+_mod-4;
                              _fourthImageInArray = _const*_numOfSlides+_mod-3;
                              _fifthImageInArray = _const*_numOfSlides+_mod-2;
                              _sixthImageInArray = _const*_numOfSlides+_mod-1;
                          }
                          k = 0;
                          while (k < _numOfSlides)
                          {
                              switch(k)
                              {
                                  case(0):
                                      img0 = new Images(imagesArray[_firstImageInArray], _w, _h, ((_w+spacer)*j)+_x+600, _y);
                                      ImageDisplayArray.push(img0);
                                      break;
                                  case(1):
                                      img1 = new Images(imagesArray[_secondImageInArray], _w, _h, ((_w+spacer)*(j-1))+_x+600, _y);
                                      ImageDisplayArray.push(img1);
                                      break;
                                  case(2):
                                      img2 = new Images(imagesArray[_thirdImageInArray], _w, _h, ((_w+spacer)*(j-2))+_x+600, _y);
                                      ImageDisplayArray.push(img2);
                                      break;
                                  case(3):
                                      img3 = new Images(imagesArray[_fourthImageInArray], _w, _h, ((_w+spacer)*(j-3))+_x+600, _y);
                                      ImageDisplayArray.push(img3);
                                      break;
                                  case(4):
                                      img4 = new Images(imagesArray[_fifthImageInArray], _w, _h, ((_w+spacer)*(j-4))+_x+600, _y);
                                      ImageDisplayArray.push(img4);
                                      break;
                                  case(5):
                                      img5 = new Images(imagesArray[_sixthImageInArray], _w, _h, ((_w+spacer)*(j-5))+_x+600, _y);
                                      ImageDisplayArray.push(img5);
                                      break;
                              }
                              ++k;
                          }
                          k = 0;
                          while (k < ImageDisplayArray.length)
                          {
                              parent_container.addChild(ImageDisplayArray[k]);
                              k++;
                          }
                      }
                 
                      function NextSlide():void
                      {
                          spacer = 10;
                          iterations++;
                          i = 0;
                          while (i != parent_container.numChildren)
                          {
                              parent_container.removeChildAt(i);
                          }
                          if (parent_container.parent)
                          {
                              removeChild(parent_container);
                              parent_container = null;
                              parent_container = new MovieClip();
                              addChild(parent_container);
                          }
                          LoadImageDisplayArray();
                          myTimer.addEventListener(TimerEvent.TIMER, CallNextSlide);
                          myTimer.start();
                      }
                     
                      function CallNextSlide(event:TimerEvent):void
                      {
                          timeline = new TimelineMax({onComplete:NextSlide()});
                          timeline.append(TweenLite.to(parent_container, 1, {x:130}) );
                      }
                  }
              }

               

               

              And here's the code for Images:

               

              package  {
                  import flash.events.IEventDispatcher;
                  import flash.events.EventDispatcher;
                  import flash.events.Event;
                  import flash.display.MovieClip;
                  import flash.display.Sprite;
                  import flash.display.Bitmap;
                  import flash.display.BitmapData;
                  import flash.filters.*;
                  import flash.filters.BitmapFilterQuality;
                  import flash.net.URLRequest;
                  import flash.net.URLLoader;
                  import flash.display.Loader;
                  import flash.display.LoaderInfo;
                  import flash.display.DisplayObject;
                  import flash.events.Event;
                  import flash.events.IOErrorEvent;
                 
                  public class Images extends MovieClip implements IEventDispatcher
                  {
                      private var parent_container:Sprite = new Sprite();
                      private var _path:String = new String("path");
                      private var _myWidth:Number = new Number(20);
                      private var _myHeight:Number = new Number(20);
                      private var _myX:Number = new Number(20);
                      private var _myY:Number = new Number(20);
                      private var _myURL:String = new String("url");
                      public var myDispatcher:IEventDispatcher= new EventDispatcher();

               

                      public function Images(path:String, myWidth:uint, myHeight:uint, myX:uint, myY:uint, myURL:String="")
                      {
                          _path = path;
                          _myURL = myURL;
                          _myWidth = myWidth;
                          _myHeight = myHeight;
                          _myX = myX;
                          _myY = myY;
                          LoadImage();
                      }
                     
                      function LoadImage():void
                      {
                          parent_container = new Sprite();
                          addChild(parent_container)
                          var req:URLRequest = new URLRequest(_path);
                          var loader:Loader = new Loader();
                          loader.load(req);
                          loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);         
                          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadedImage);
                      }

               

                      function LoadedImage(e:Event):void
                      {
                          myDispatcher.addEventListener(Event.COMPLETE, ImDone);
                          var loaderInfo:LoaderInfo = e.target as LoaderInfo;
                          var displayObject:DisplayObject = loaderInfo.content;
                          displayObject.width = _myWidth;
                          displayObject.height = _myHeight;
                          parent_container.addChild(displayObject);
                          parent_container.x = _myX;
                          parent_container.y = _myY;
                      }
                     
                      public function ImDone():void
                      {
                          trace("I'm done!");
                      }

               

                      function ioErrorHandler(event:IOErrorEvent):void {
                          trace("ioErrorHandler: " + event);
                      }
                  }
              }

               

               

              TIA,

              Beno

              • 4. Re: removeChild/addChild Problem
                beno12345 Level 1

                Oops. I set _numOfSlides to 6 and that's necessary until I rework it a bit. I set _totalImages to 12 although I think you could run with whatever. And thanks also to Kglad for pitching in again.

                Beno

                • 5. Re: removeChild/addChild Problem
                  Ned Murphy Adobe Community Professional & MVP

                  What is your basis for thinking that there is a glitch where you say there is?  You should follow kGlad's mention and just remove that unnecessary removeChild code... removing and immediately re-adding is wasted processing.  See if your glitch is still evident, which it most likely will be.

                  • 6. Re: removeChild/addChild Problem
                    beno12345 Level 1

                    I'm sorry. Removing the following code:

                     

                                while (i != parent_container.numChildren)
                                {
                                    parent_container.removeChildAt(i);
                                }
                                if (parent_container.parent)
                                {
                                    removeChild(parent_container);
                                    parent_container = null;
                                    parent_container = new MovieClip();
                                    addChild(parent_container);
                                }

                     

                    did indeed take out the blinking; however, it also took out the tweening, such that instead of taking the one second indicated in my code to transit along the x axis, it happens immediately. Now why is that?

                    TIA,

                    Beno

                    • 7. Re: removeChild/addChild Problem
                      beno12345 Level 1

                      PS: To be clear, when I do the removeChild/addChild, it blinks but it does correctly tween. Solely removing that block, while it does get rid of the blinking, for some reason screws up the tweening.

                      Beno

                      • 8. Re: removeChild/addChild Problem
                        beno12345 Level 1

                        PPS: I changed this:

                         

                                    timeline = new TimelineMax({onComplete:NextSlide});
                                    timeline.append(TweenLite.to(parent_container, 0, {x:150}) );

                         

                         

                        to this:

                         

                                    TweenLite.to(parent_container, 1, {x:130, onComplete:NextSlide});

                         

                        but it didn't clear up the problem.

                        Beno

                        • 9. Re: removeChild/addChild Problem
                          beno12345 Level 1

                          PPPS: The problem does not have anything to do with the timer value here being set to 0:

                           

                                  public function Slides(_numOfSlides:int, _totalSlides:int, _w:int, _h:int, _x:int, _y:int):void
                                  {
                                      addChild(parent_container);
                                      var container:MovieClip = new MovieClip();
                                      spacer = 10;
                                      XMLLoader();
                                      AddSlides();
                                      TweenLite.to(parent_container, 0, {x:150, onComplete:NextSlide});
                                  }

                           

                          since this simply positions it the first time (didn't have to tween, obviously). The repetitive tween occurs in NextSlide();

                          Beno

                          • 10. Re: removeChild/addChild Problem
                            beno12345 Level 1

                            Through testing I have discovered that the problem is (what appears to my foolish, untrained eye to be) a glitch in the greensock s/w. Credit to Kglad, extra thanks to Ned

                            Beno

                            • 11. Re: removeChild/addChild Problem
                              GreenSock Level 1

                              I'm sorry you're running into trouble, Beno, and it would be easier to just claim that it's a "glitch" in GreenSock code, but you have yet to provide a shred of reproducable evidence to back up that claim. In fact, if anyone searches the 78 posts you've submitted in the GreenSock forums, I think they'll see that in virtually every case the problems you reported had nothing to do with GreenSock code and everything to do with mistakes on your end. That's totally fine, though - the forums are there to help you identify and correct mistakes. But if you want to improve the chances of getting folks to help you, I'd recommend the following:

                               

                              1) Isolate the problem in a separate FLA that has only the absolutely essential code to reproduce the problem. Post that FLA file for others to review and compile. I noticed that many times your posts have a bunch of extra non-essential code that can tend to just confuse the issue. If you think doing a removeChild() and then addChild() somehow screws up TweenLite (I can assure you it doesn't), create a separate FLA that only does a removeChild() then an addChild() and then a tween. See if it breaks. If it doesn't, start building it up to do more until it breaks. Only post your question in the forums or mailing list after you've gone through this isolation process. I noticed that the guys on the figleaf list got ticked with you after they felt that it was obvious that you weren't doing your homework and were abusing the list. I'm not saying they're correct about that - I'm just trying to give you some advice about how to get the most out of forums and lists.

                               

                              2) Don't throw out accusations about there being a glitch/bug in someone else's code until you've provided hard evidence to the author and given him/her a chance to respond. You cross posted about this issue in the GreenSock forums and have yet to provide the evidence that was requested.

                               

                              For anyone interested in following the discussion, here's a link to the thread in the GreenSock forums:

                              http://forums.greensock.com/viewtopic.php?f=1&t=4534

                               

                              Best wishes to you, Beno. I'll gladly look at any concise FLAs you want to provide that relate to the issue you posted about. I'm confident that we can identify the problem if we get that file from you.

                              • 12. Re: removeChild/addChild Problem
                                beno12345 Level 1

                                You're kind and helpful. I tend to think that if I can't see the

                                problem that it must be a glitch in the s/w. Frankly, I'm that way in

                                all aspects of my life. It's not wrong of me; rather, it's a "glitch"

                                in my programming lol, as almost invariably I later discover my

                                mistake. I don't say such things maliciously, I honestly believe them.

                                 

                                With regard to this problem, I have tracked it down, but not resolved

                                it. I was going to post the problem with the solution once I

                                discovered it to your forum. I've asked for help in the Adobe Flash

                                forum, but I guess it's outwitted even them. Here's that post, should

                                you be interested:

                                 

                                Hi;

                                 

                                I think this will be my last question for a while. I have this code:

                                 

                                 

                                 

                                        function NextSlide():void

                                        {

                                            spacer = 10;

                                            iterations++;

                                            LoadImageDisplayArray();

                                            myTimer.addEventListener(TimerEvent.TIMER, CallNextSlide);

                                            myTimer.start();

                                        }

                                 

                                        function CallNextSlide(e:TimerEvent):void

                                        {

                                            TweenLite.to(parent_container, 2, {x:150, onComplete:NextSlide()});

                                        }

                                 

                                 

                                 

                                This is part of an infinite loop which enables me to have a serie of

                                slides go across the screen and wraps around after the last image is

                                put into the "slide show"; that is, it restarts back with the first

                                image without a break. Works well However, that final tween never

                                really tweens; that is, there's no sliding in over the time interval,

                                because it matches the time interval of myTimer, which controls

                                everything. How can I make it slide?

                                 

                                 

                                And in answering a clarifying question:

                                 

                                Yes, parent_container is updated in LoadImageDisplayArray. Here's the snippet:

                                 

                                 

                                 

                                            while (k < ImageDisplayArray.length)

                                            {

                                                parent_container.addChild(ImageDisplayArray[k]);

                                                k++;

                                            }

                                 

                                 

                                 

                                I repeatedly add that listener to myTimer to tween it. What happens is

                                that I clear out the old images and enter new ones (5 of 6 of which

                                are "old images" but now repositioned) and then tween parent_container

                                the same distance from the same starting point, but giving the

                                illusion that it's one continuous long chain of images. myTimer

                                executes repeatedly. It's essential that it do so, otherwise my

                                infinite loop creates an overflow of data because everything would

                                otherwise get processed simultaneously.

                                 

                                Thanks,

                                Beno

                                • 13. Re: removeChild/addChild Problem
                                  kglad-zqbLf4 Level 3

                                  in years of use and scores of applications, i've only had one problem with the as2/as3 gs tween classes and that was due to a bug in the onEnterFrame method that the gs classes, and most other tween classes, use.  that problem was not due to any gs coding.

                                  • 14. Re: removeChild/addChild Problem
                                    kglad-zqbLf4 Level 3

                                    i can't really determine what you're doing with that code but you may be over-writing a tween.  try using the overwrite parameter and assigning it to false.

                                    • 15. Re: removeChild/addChild Problem
                                      GreenSock Level 1

                                      I can see one problem for sure, and it's probably what's causing the behavior you described. You're using the wrong syntax for the onComplete - you're calling the method IMMEDIATELY because whenever you put "()" on the end of a method name, it tells Flash to call that method right away.

                                       

                                      BAD: TweenLite.to(parent_container, 2, {x:150, onComplete:NextSlide()});

                                      GOOD: TweenLite.to(parent_container, 2, {x:150, onComplete:NextSlide});

                                       

                                      It's very difficult to see exactly what you're doing with your code there which is why I've asked for a sample FLA that clearly demonstrates the problem. When we have a simple FLA that can be published on our end, it's much, much easier to see the problem in context and troubleshoot effectively. Please don't post your production file(s) though - just create a very, very simplified FLA that isolates this particular issue with the minimal amount of code. This will save everyone a lot of time.

                                       

                                      For what it's worth, there's a sample slide show that uses TweenLite and LoaderMax at http://www.greensock.com/as/LoaderMax/slideshow.zip - you might be able to look at some techniques in there that would apply to your scenario. It loops the same way yours does and auto-advances.

                                      • 16. Re: removeChild/addChild Problem
                                        beno12345 Level 1

                                        Hi;

                                        I have played with adding the parens at the end of the onComplete fn

                                        call and it doesn't make a diff in this case, but thanks for helping

                                        me understand. Looking at the code you gave me...thanks! Here's the

                                        example you requested. Please ignore the name of the folder ("junk").

                                        It just helps me remember that the contents are disposable and it

                                        isn't a client's folder!

                                        Thank you,

                                        Beno

                                        • 17. Re: removeChild/addChild Problem
                                          GreenSock Level 1

                                          Where's the file you mentioned? I didn't see any attachments to your post.

                                          • 18. Re: removeChild/addChild Problem
                                            beno12345 Level 1

                                            It was probably too big. Please go here:

                                            http://creative.vi/SlideShowExample.zip

                                            TIA,

                                            Beno

                                            • 19. Re: removeChild/addChild Problem
                                              GreenSock Level 1

                                              The reason it looks like the tween isn't working is because you're tweening to x:150 but the object is ALREADY at x:150. There's nowhere to go. Try adding an alpha to the tween or some other property and you'll see that it is indeed working.

                                              • 20. Re: removeChild/addChild Problem
                                                beno12345 Level 1

                                                I'm afraid it's more complicated than that. I added the alpha change

                                                as you suggested, but the outcome was as I anticipated. The program

                                                enters all the images (7 I believe) in a container then tweens the

                                                container across, then removes all the children, increments the

                                                variable that determines which children are added, adds the new

                                                children, repositions the container at the original position and

                                                re-tweens, giving the illusion that there is a continuous chain of

                                                images scrolling across, when in fact there are only ever 7 Clever.

                                                Now, can I get it working lol?

                                                TIA,

                                                Beno

                                                • 21. Re: removeChild/addChild Problem
                                                  beno12345 Level 1

                                                  Hey;

                                                  Your response indicated you hadn't yet played the swf file. If you

                                                  have time and really do want to help me with this:

                                                  1) Play the swf file so you can visually see what works and what doesn't.

                                                  2) The problem is in that repeated timer call. If I change the value

                                                  of when the action fires (e.g., from 1 sec to 2), it completely alters

                                                  the tween timing; therefore, it seems to control the same. And I can't

                                                  see how to get rid of it, since if I do, I overflow the stack.

                                                  3) If I put it up on the web, it doesn't work. Frankly, I could live

                                                  with no nice tween, but obviously not if it doesn't work online.

                                                  TIA,

                                                  Beno

                                                   

                                                  --

                                                  The Logos has come to bear

                                                  http://logos.13gems.com/

                                                  • 22. Re: removeChild/addChild Problem
                                                    carl schooff Level 3

                                                    please provide the code that  "repositions the container" as you claim.

                                                     

                                                    parent_container is only mentioned in a few places in your code and where it is mentioned it's x property is at or tweening to 150.

                                                    again, you can't tween something to 150 if it is already there.

                                                     

                                                    after seeing GreenSock's suggestion, I looked at your code and it is overwhelmingly obvious that:

                                                     

                                                    a) he did look at your code

                                                    b) his suggestion is the absolute first thing you need to address in order to move forward with your problem

                                                     

                                                     

                                                    Also, replying with

                                                     

                                                    I'm afraid it's more complicated than that. I added the alpha change

                                                    as you suggested, but the outcome was as I anticipated

                                                     

                                                     

                                                    how is anyone supposed to know what you anitcipated? All you did was re-iterate how you want it to work, but didn't bother to explain how GreenSock's test suggestion didn't work.

                                                     

                                                    what was the outcome? did it fade once, not at all?

                                                    • 23. Re: removeChild/addChild Problem
                                                      carl schooff Level 3

                                                      here is a super simplistic implementation of the "infinite scroll effect" you are trying to attain:

                                                       

                                                      http://www.snorkl.tv/dev/infiniteScroll/

                                                       

                                                      click the toggle mask button to see how the clips are being re-positioned.

                                                       

                                                      this is provided as an attempt to display:

                                                       

                                                      • the core of what you are trying to do can be achieved with very very little code.
                                                      • child clips and the container do not need to be removed and re-added to display list
                                                      • there is no need for elaborate array re-writing routines including numerous loops and switches... if by chance you do need the list of items to be managed by an array, you could simply use built in array methods like splice / pop / unshift to chop off the last item and move it to the front.

                                                       

                                                       

                                                      the example I provided could be much more dynamic to account for spacing between images and perhaps shifting more than one clip at a time. some stuff could also be built in to make all the sliding and shift amounts based on width of viewable area, width of each clip, distance to tween etc. I wanted to keep it bare-bones.

                                                       

                                                       

                                                      I've found its best to start with something small that works and add complexity as you go.

                                                       

                                                      Once you hit a point where nothing seems to work as planned, you should try to isolate the problem in a separate file with as little additional fluff as possible and add functionality until it breaks... as has been suggested many times before. This also makes it easier for others to troubleshoot your problem so they don't have to sift through 100s of lines of non-related code.

                                                       

                                                      In closing I am not suggesting that you use my code or that is superior in some way. Just want to provide an alternate, concise look at exactly what needs to happen in regards to theory and functionality. There are many ways of approaching this.

                                                       

                                                       

                                                       

                                                       

                                                       

                                                       

                                                      • 24. Re: removeChild/addChild Problem
                                                        beno12345 Level 1

                                                        I'm embarrassed to admit I'm having trouble understanding my own code!

                                                        It's a hodge-podge...no wonder you all are having trouble

                                                        understanding it! So, yes, the alpha tween does tween, and it tweens

                                                        over the allotted time frame once (of course, since it doesn't tween

                                                        back). During that first tween, x does not "tween" at all. I put tween

                                                        in quotes, because I can't figure out how I get x to tween at all, but

                                                        it does indeed tween as one can plainly see by playing the swf. I

                                                        traced the value of x just prior to the tween in CallNextSlide() and

                                                        it traces as 150 the same value to which x supposedly tweens! If I

                                                        change the value of x in the tween to, say, 0, it takes 2 seconds (as

                                                        per the tween) in the first call of the tween to travel "to the left"

                                                        to its new position, then it "snaps" over "to the right" with each new

                                                        call. The only place where CallNextSlide() is called is from

                                                        NextSlide() where it is called by the addEventListener Timer event.

                                                         

                                                        Thank you for your infinite scroll. I will rebuild my code based on

                                                        yours. I may be back with questions; however today is Thursday, I have

                                                        stuff to do for a client to pick up a check tomorrow then I'm off to

                                                        the Dominican Republic for a week where I will still do work but it

                                                        may be a few days before I have a chance to get to this (like probably

                                                        Monday).

                                                         

                                                        "I've found its best to start with something small that works and add

                                                        complexity as you go." Yeah, lol. I have a problem with that. I think

                                                        my problem is I can't easily or clearly see the small thing and it

                                                        mushrooms on me trying to see it anything at all. As I've said before

                                                        on lists, I am no natural at this. I just find reverse-engineering

                                                        creation absolutely fascinating, and that's why I'm here.

                                                         

                                                        "Once you hit a point where nothing seems to work as planned, you

                                                        should try to isolate the problem in a separate file with as little

                                                        additional fluff as possible and add functionality until it breaks...

                                                        as has been suggested many times before. This also makes it easier for

                                                        others to troubleshoot your problem so they don't have to sift through

                                                        100s of lines of non-related code." Yeah. I didn't realize how caught

                                                        up in the forest I was that I'd lost sight of the trees. I thought it

                                                        was obvious that the problem is at the tween. And maybe it is. But I

                                                        haven't got a clue now!

                                                         

                                                        Thank you so much.

                                                        Beno

                                                        PS I make a much better entertainer than programmer, and later this

                                                        year I'll go pro as a songwriter/singer/dancer of Latin Caribbean

                                                        music. Not that I'll give up programming because I enjoy it

                                                        • 25. Re: removeChild/addChild Problem
                                                          beno12345 Level 1

                                                          Hi;

                                                          Thank you again, Meglomor, for your code. I'm trying to get this

                                                          working in a class as opposed to coding from the timeline, and without

                                                          importing things from the library. At this point I would usually ask

                                                          questions of the Adobe Flash discussion list, but since it's your

                                                          code, I'm asking you first. Here's my revised code:

                                                           

                                                          package  {

                                                               import com.greensock.*;

                                                               import flash.display.MovieClip;

                                                               import flash.display.Sprite;

                                                               import flash.events.Event;

                                                               import flash.events.MouseEvent;

                                                                

                                                               [SWF(width="1008", height="548")]

                                                                

                                                               public class InfiniteScroll extends MovieClip {

                                                                    private var parent_mc:MovieClip = new MovieClip();

                                                                    private var mask_mc:MovieClip = new MovieClip();

                                                                    private var mc:MovieClip = new MovieClip();

                                                                    private var btn:Sprite = new Sprite();

                                                           

                                                                    public function InfiniteScroll()

                                                                    {

                                                                         // array methods like splice / pop / unshift to chop off the last

                                                          item and move it to the front.

                                                                         var startX:Number=parent_mc.x;

                                                                         addChild(parent_mc);

                                                                         toggleMask();

                                                                         AddPics();

                                                           

                                                                         function AddPics():void

                                                                         {

                                                                              var colors:Array = new Array("0xff0000", "0x00ff00", "0x0000ff", "0xffff00")

                                                                              var i:int=0;

                                                                              while (i < 4)

                                                                              {

                                                                                   var square:MovieClip = new MovieClip();

                                                                                   square.graphics.beginFill(colors[i]);

                                                                                   square.graphics.moveTo(0,0);

                                                                                   square.graphics.lineTo(100,0);

                                                                                   square.graphics.lineTo(100,100);

                                                                                   square.graphics.lineTo(0,100);

                                                                                   square.graphics.lineTo(0,0);

                                                                                   square.graphics.endFill();

                                                                                   i++;

                                                                                   parent_mc.addChild(square);

                                                                              }

                                                                              scrollIt();

                                                                         }

                                                           

                                                                         function scrollIt():void

                                                                         {

                                                                              TweenMax.to(parent_mc, .5, {x:"100", onComplete:reset});

                                                                         }

                                                           

                                                                         function reset()

                                                                         {

                                                                              //move all clips over to the right

                                                                              for each (var mc in parent_mc)

                                                                              {

                                                                                   trace('xxx');

                                                                                   mc.x+=100;

                                                                                   if (mc.x==400)

                                                                                   {

                                                                                        //take the right-most one and set it back to the left

                                                                                        trace("found end mc = " + mc.name);

                                                                                        mc.x=0;

                                                                                   }

                                                                              }

                                                                              //shift the parent so it looks like nothing moved

                                                                              parent_mc.x=startX;

                                                                              //scroll it again after 1 second

                                                                              TweenLite.delayedCall(1, scrollIt);

                                                                         }

                                                           

                                                                         btn.addEventListener(MouseEvent.CLICK, toggleMask)

                                                           

                                                                         function toggleMask(e:Event = null):void

                                                                         {

                                                                              parent_mc.mask = (parent_mc.mask) ? null : mask_mc

                                                                         }

                                                                    }

                                                               }

                                                          }

                                                           

                                                          Now I know the button doesn't work and I don't care about that right

                                                          now. However, you'll notice a trace in there that doesn't trace. All

                                                          the way up to that point I can trace stuff, so apparently The problem

                                                          likes in my not being able to call mc's from the parent_mc. This

                                                          notation is new to me so I'm a bit lost to begin with. Nothing prints

                                                          to screen, either, and there are no errors. If you want to see this in

                                                          action, just make an empty fla that calls this class.

                                                          TIA,

                                                          Beno