9 Replies Latest reply on May 11, 2008 11:11 PM by

    Using Var (i=o, i<10, i++)

      Hello everyone,

      Hope someone can help me with this. I have started a slide show for a car site which you can view here:

      http://www.virtuallglab.com/projects.html

      I also attach an example of the code.
      My problem is this not very flexible as i have a few pictures to show, and the client might even add more, so I would like to insert this code within a function using a variable .
      At the moment, I'm using an onMotionFinished that calls the second set of pictures to start animating when the first has finished.

      Any help appreciated,
      Thanks
        • 1. Using Var (i=o, i<10, i++)
          NecroSaint Level 1
          Ok i'm sorry if i'm not being very helpful here, but wouldnt it be a lot easier and smoother if you did this as a simple animation instead of action scripting it. This way you wont get that text changing while it is halfway in the screen. I know it will take longer, but i just think it will be a lot easier and smoother.

          Sorry i can't help you with your problem., but you seriously might want to consider just putting this as a straight forward animation if you don't want any extra functions included.


          *EDIT* - I rewatched the animation after and the text worked fine, before it was going over the car and then changing to the text relating to car as it went out of screen. Sorry for making that mistake :S.
          • 2. Re: Using Var (i=o, i<10, i++)
            Level 7
            If you put it on a timeline how would you solve his question:

            My problem is this not very flexible as i have a few pictures to show, and
            the
            client might even add more, so I would like to insert this code within a
            function using a variable .


            It would not be dynamic on the timeline, so it would not work for this.


            --
            Dave -
            www.offroadfire.com
            Head Developer
            http://www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            1 person found this helpful
            • 3. Re: Using Var (i=o, i<10, i++)
              NecroSaint Level 1
              ah, true :S sorry :P
              • 4. Using Var (i=o, i<10, i++)
                Thanks for our replies

                Yes, images and text must be imported from external files so the client can change them easily, as a matter of fact, even if that wasn't the case I would still use actionscript for smoother animations using the tween class, and it's much easier to update.

                I thought it would be as easy as putting the above script within a function such as this:

                function carPicAnim () {
                for (var (i=0, i<10, i++) {

                // current script here with numbers replaced by i.
                // but I can't get it to work, I probably write something wrong like here:

                leftHolder.loadMovie("pics/(i).jpg","pic1",leftHolder.getNextHighestDepth());

                }
                }

                any suggestion

                Thanks
                • 5. Re: Using Var (i=o, i&lt;10, i++)
                  *EDIT* - I rewatched the animation after and the text worked fine, before it was going over the car and then changing to the text relating to car as it went out of screen. Sorry for making that mistake :S.


                  I just watch it again and I did see the bug you mentioned...in fact there is another bug, as when the slide reaches the 8th picture (there are 10 in total), it loops on itself and does go to the 9th picture. This is quite strange as it is the exact same script as the other pictures. problem I've got at the moment is that I need to repeat the above code 10 times for each picture and that might cause so bug for some reason. I really need someone to teach me how to use the var i with the for statement.....

                  Many thanks
                  • 6. Using Var (i=o, i&lt;10, i++)
                    Ned Murphy Adobe Community Professional & MVP
                    Since you are using AS1/2 you don't need to include the "var" in the loop for i.

                    You can simply use for(i=0; i<10; i++){....}

                    And you want to use semicolons rather than commas.
                    1 person found this helpful
                    • 7. Re: Using Var (i=o, i&lt;10, i++)
                      quote:

                      Originally posted by: NedWebs
                      Since you are using AS1/2 you don't need to include the "var" in the loop for i.

                      You can simply use for(i=0; i<10; i++){....}


                      Thanks, so should I write it like this:


                      leftHolder.loadMovie("pics/(i).jpg","pic ",leftHolder.getNextHighestDepth());

                      I have tried to trace pics/(i).jpg, or with square brakets or without anything but it returns Undefined. That's the bit Imight be writing wrong

                      Thanks
                      • 8. Re: Using Var (i=o, i&lt;10, i++)
                        Ned Murphy Adobe Community Professional & MVP
                        For the loadMovie line, it's better to build variables outside the function call, as in...

                        var picToLoad = "pics/"+i+".jpg";
                        leftHolder.loadMovie(picToLoad,"pic",leftHolder.getNextHighestDepth());

                        This assumes you are only using numbers as image names (0.jpg, 1.jpg, etc)
                        1 person found this helpful
                        • 9. Re: Using Var (i=o, i&lt;10, i++)
                          quote:

                          Originally posted by: NedWebs
                          For the loadMovie line, it's better to build variables outside the function call, as in...

                          var picToLoad = "pics/"+i+".jpg";
                          leftHolder.loadMovie(picToLoad,"pic",leftHolder.getNextHighestDepth());

                          This assumes you are only using numbers as image names (0.jpg, 1.jpg, etc)



                          Thanks a lot Ned