11 Replies Latest reply on Feb 1, 2012 1:52 AM by ineedsomehelpplz

    Flash as3 tween with array problems

    ineedsomehelpplz

      Hi,

       

      i am sorry for bad english first.

       

      i do have some problems with flash AS3 tween function

       

      i do have some sprites with bitmaps from library inside,

      thouse bitmaps habe starting positions.

       

      on click number of item (code "2"), all the bitmaps have to move to the middle (global)

      they do move, but if another button is pressed, and i press button -2 again, first array element wont get to the right place,

       

      tracing arrayelement remains on zero

       

       

      function onClickButton(e:MouseEvent)

      {

                var number = 2;

                for (var i:int=0; i<=4; i++)

                {

       

                          if (i == number)

                          {

                                    var xTween = new Tween(myIcons[i],"x",Strong.easeOut,myIconsX[i],middle,1,true);

      // myIcons array with icons

      //myIconsX aaray with x position of the icons

       

                          }

                          else

                          {

                                    var xTween = new Tween(myIcons[i],"x",Strong.easeOut,myIconsX[i],myIconsX[i] + middle - myIconsX[number],1,true);

       

       

                          }

                          myIconsX = [bitmap1.x,bitmap2.x,bitmap3.x,bitmap4.x]

       

       

                }

       

      }

       

       

      its just the first element, all others are working

        • 1. Re: Flash as3 tween with array problems
          Ned Murphy Adobe Community Professional & MVP

          Are you saying that myIcons[0] does not do what all the others do?

           

          Why is your loop going thru 5 iterations (0 thru 4 inclusive) while your myIconsX array only has 4 values?  What are bitmap1 thru bitmap4 in relation to anything else your code processes?  Are they the myIcons objects?

          • 2. Re: Flash as3 tween with array problems
            ineedsomehelpplz Level 1

            hi,

             

            thanks for the answer, i forgot to put the "..." in my array, loop and array do have same amount, its the example.

             

            yes myIconsX[0] jumps for the first time to the right position, jumps not tween, and does something interesting, jumping away for four times, then stop

             

             

             

            var first : bitmap1 = new bitmap1();

            var mySpritefirst :Sprite = new Sprite();

            first.y = 0;

            mySpritefirst.addChild(first);

            addChild(mySpritefirst);

            mySpritefirst.x = 0;

             

            its working with all other icons, but first

             

            i hope, i made no mistakes in example code

            thanks

            • 3. Re: Flash as3 tween with array problems
              Ned Murphy Adobe Community Professional & MVP

              For the line...

               

              myIconsX = [bitmap1.x,bitmap2.x,bitmap3.x,bitmap4.x]

               

              it is define after the Tweens are establish in the first of the loops.  What values are in that array before the looping starts?

               

              I do not see where you define that variable before that, so the first object that goes thru your for loop in the function might not have a myIconsX[i] and myIconsX[number] values to use in the Tween.

              • 4. Re: Flash as3 tween with array problems
                ineedsomehelpplz Level 1

                before

                 

                mySpritefirst.x = 0;

                 

                sry its should be

                 

                bitmap1.x = 0

                 

                i just tooke the exaple in different codes :S

                 

                before my for loop begins all x coordinates are defined

                after the loop all the other array elements are updated, but not the first

                 

                 

                 

                /*

                 

                var first : bitmap1fromlibrary = new bitmap1fromlibrary ();

                var mySpritefirst :Sprite = new Sprite();

                first.y = 0;

                mySpritefirst.addChild(first);

                addChild(mySpritefirst);

                mySpritefirst.x = 0;

                */

                mySprite.x = bitmap1.x;

                • 5. Re: Flash as3 tween with array problems
                  ineedsomehelpplz Level 1

                  may be i should write, i splited all the bitmaps, every bitmap has a layer which has action code which inserts objects and another layer has imports and functions which i am using in every bitmaplayer such as definition of arays

                   

                  haha, its compicated

                   

                  what i really want is, to implement a coverflow, but with different sized items, so i cant take is dynamicly, every item has different size and a different distance to the next

                   

                  so ive placed all the bitmaps and if i press a button which is every bitmap, it should move to the middle

                   

                  so they do move to the middle but the first is always jumping for few times, i do not have any debugging like in java or c, so its compicated for me

                  • 6. Re: Flash as3 tween with array problems
                    ineedsomehelpplz Level 1

                    may be i can try to put "continue" in my loop, like i would do it in objective c ... i am not sure

                    • 7. Re: Flash as3 tween with array problems
                      Ned Murphy Adobe Community Professional & MVP

                      You said...

                       

                      before my for loop begins all x coordinates are defined

                      after the loop all the other array elements are updated, but not the first

                       

                      but you didn't indicate anything regarding the status of the myIconsX array.  It does not get anything assigned until after the first loop of the for loop.  So what I am saying is that the first object being processed in the loop might not have  the value used in the Tween...

                       

                      var xTween = new Tween(myIcons[i],"x",Strong.easeOut,myIconsX[i],myIconsX[i] + middle - myIconsX[number],1,true);

                      • 8. Re: Flash as3 tween with array problems
                        ineedsomehelpplz Level 1

                        hi, thanks for your help

                         

                         

                        var myIconsX: Array = [bitmap1.x,bitmap2.x,bitmap3.x,bitmap4.x,..];

                        var myIcons: Array = [bitmap1,bitmap2,bitmap3,bitmap4,..];

                         

                        this is defined before in the other layer with some other function

                        • 9. Re: Flash as3 tween with array problems
                          ineedsomehelpplz Level 1

                          its just the first icon :S

                          if you give me your email, or dropbox acc , i could just give you the whole examle

                          • 10. Re: Flash as3 tween with array problems
                            ineedsomehelpplz Level 1

                            i do have this compiler error because of duplicated var xTween,

                            i eliminated it and just defined xTween2

                            it had no effect :S

                             

                            its always the first, may be i just place unvisible picture

                            • 11. Re: Flash as3 tween with array problems
                              ineedsomehelpplz Level 1

                              i found no obvious mistakes in my humble as3,

                              so i ve just placed a unvisible movieclip in the first array element and ....

                               

                              it works perfekt!

                               

                              i have no debugging tools to figure out, what happens, so i will say its a BUG!

                               

                              buggy buggy flash

                               

                              i would love to know, what is my mistake to improove anyway