10 Replies Latest reply on Jan 7, 2011 11:03 AM by kglad

    Recalculating space between objects on a fly in slide show...

    lanawylma2000 Level 1

      Hi All.. I"m hoping someone can help me with this - and thank you ahead of time!

       

      I'm working with a slide show that has products of different widths. The idea is to make sure that when user clickes  on the next/back buttons and the next (or prev) product shows up - to make sure that the product is not clipped either on left of stage (or live area) or right..

       

      The only way I can think of is that flash needs to recalculate the space between products depending on which products are currently showing... This is the part of code where I'm pretty sure this calculation needs to happen (back button has basically same code):

       

      where itemSpace is the space is the space between products and the and the product_mc is any product.. all products are being called via XML.. If anyone could put in in the right direction here - I'd REALLY appreciate it..

       

      _root.button_next.onRelease = function(){
          trace("button_next onRelease");
          if (_root.totalImages - currentIndex > 5)
          {
              _root.xTargetMC += -1 * (_root.MC["coffee_maker"+ currentIndex].product_mc._width * 2 + _root.itemSpace);
              if (currentIndex > 0)
                  _root.xTargetMC += 1 * firstPosX;
                 
              currentIndex += 1;
              if (currentIndex > 0)
              {
                  _root.button_back._visible = true;
              }
                 
              if (currentIndex == _root.totalImages - 5)
              {
                  _root.button_next._visible = false;
              }
          }
      }

        • 1. Re: Recalculating space between objects on a fly in slide show...
          kglad Adobe Community Professional & MVP

          nothing is positioned with that code.  some of those variables may be used for positioning but the actual positioning is occuring elsewhere.

           

          in addition, to determine how objects should be positioned we'll need to know what's displayed.  for example, are there 3 items being positioned/displayed with each button press or 5 items or some variable number?

          • 2. Re: Recalculating space between objects on a fly in slide show...
            lanawylma2000 Level 1

            Thanks for your reply Kglad!

             

            The variables are being set up here, on frame 1:

             

            var xmlDoc:XML = new XML();
            var imageList = new Array();
            var totalImages:Number;
            var currentImages:Number = 0;

             

            var firstPosX = 25;
            var itemPosX = firstPosX;
            var itemSpace = 30;

             

             

            Than here's the complete script from that frame (plus it has same function for back button, but going back):

             

            xTargetMC = 0;
            var currentIndex = 0;

             


            if (_root.totalImages > 5)
            {
                _root.button_next._visible = true;
            }

             

            stop();

             

            _root.button_next.onRelease = function(){
                trace("button_next onRelease");
                if (_root.totalImages - currentIndex > 5)
                {
                    _root.xTargetMC += -1 * (_root.MC["coffee_maker"+ currentIndex].product_mc._width * 2 + _root.itemSpace);
                    if (currentIndex > 0)
                        _root.xTargetMC += 1 * firstPosX;
                       
                    currentIndex += 1;
                    if (currentIndex > 0)
                    {
                        _root.button_back._visible = true;
                    }
                       
                    if (currentIndex == _root.totalImages - 5)
                    {
                        _root.button_next._visible = false;
                    }
                }
            }

             

            Also, there's this script - may be that's where it's set up:


            onClipEvent (enterFrame) {
                xMC = getProperty(_root.MC, _x);
                moveMC = _root.xTargetMC-xMC;
                setProperty(_root.MC, _x, xMC+(moveMC/4));
            }

             

             

            There are 5 items originally on stage, than, when you click on arrows, it increments/decrements by one product, however, all the products have different widths and since the itemSpace (space between products) is hardcoaded - some of the products get cut off on one side or the other..

             

             


            • 3. Re: Recalculating space between objects on a fly in slide show...
              kglad Adobe Community Professional & MVP

              which items are on stage?  currentIndex-2,currentIndex-1,currentIndex,currentIndex+1 and currentIndex+2?

              • 4. Re: Recalculating space between objects on a fly in slide show...
                lanawylma2000 Level 1

                Based on Output Panel it's currentIndex: 0, currentIndex: 1, currentIndex:2. Each current Index per click. One of the currentIndex being shown on stage at a time..

                 

                There are 7 products all together - only 5 can show at a time and each click increments 1 product - so, 3 clicks..

                 

                I just tested it by adding more products to produce more clicks - and in outputPanel I got currentIndex3..

                 

                so.. I guess I need to calculate the itemSpace for each currentIndex..

                • 5. Re: Recalculating space between objects on a fly in slide show...
                  lanawylma2000 Level 1

                  So.. I'm thinking I need to create some kind of boundingBox to reference the width..(I need to leave space for arrows on sides so best not to use stage..) and than devide that by current index width.. and devide by 4 and use that instead of itemSpace?

                   

                  So, I just did this:

                   

                  _root.button_next.onRelease = function(){
                      trace("button_next onRelease");
                      if (_root.totalImages - currentIndex > 5)
                      {
                          _root.xTargetMC += -1 * (_root.MC["coffee_maker"+ currentIndex].product_mc._width + ((mask_mc._width / currentIndex._width))/4);

                   

                  and now in output panel I still get currentIndex0, currentIndex1, currentIndex2, - but none of my products are moving... agghhh.. and there are no errors..

                  • 6. Re: Recalculating space between objects on a fly in slide show...
                    kglad Adobe Community Professional & MVP

                    do you know which object corresponds to index = 0?  if yes, where is that object when your app starts?  the left side of the stage?

                    • 7. Re: Recalculating space between objects on a fly in slide show...
                      lanawylma2000 Level 1

                      Well.. the products are in a movie clip with Instance name of MC, the buttons script is located inside of MC.. Also, all the products are contained within MC. When the app starts MC is on the right, than there's a motion tween with MC moving to left... so based on that I think index = 0 corresponds to MC and starts on the right..

                       

                      Also, on each key frame of the MC Motion tween, is this script:

                       

                      onClipEvent (enterFrame) {
                          xMC = getProperty(_root.MC, _x);
                          moveMC = _root.xTargetMC-xMC;
                          setProperty(_root.MC, _x, xMC+(moveMC/4));
                      }

                      • 8. Re: Recalculating space between objects on a fly in slide show...
                        kglad Adobe Community Professional & MVP

                        i don't see any easy way to fix that code.  the spacing is assigned elsewhere and does not change when you change the currentIndex.  that will need to be changed which will change the way your app works.

                         

                        what will probably work best is to eliminate that master movieclip MC that contains the objects seen on-stage and tween each of the 5 on-stage objects (5 tweens).  that will require removing all the tweening code you currently have and creating new code.

                        • 9. Re: Recalculating space between objects on a fly in slide show...
                          lanawylma2000 Level 1

                          Yes, I see what you mean - thank you very much for all your help on this!!