2 Replies Latest reply on Apr 13, 2013 4:49 PM by JonnyDL

    Passing varibles

    JonnyDL

      Im designing a swf that will dynamicallyload in pics and tween them. Since the widths of the imges will differ I want to take that make a vaiable based on the images width - the visibale space available and pass it into a tween.

      I can get that info in a listener, but I can't seem to pass it out into a tween. Below is the script I'm using just to see results.

      Can anyone help?

       

      Pics = new Array("Waterfall.jpg","Pool.jpg","Cottage.jpg")

       

      _global.loc;

       

      TopShelf_mc.swapDepths(4);

       

      this.createEmptyMovieClip("mcHolder", 3);

      var ClipListener:Object = new Object();

      ClipListener.onLoadInit = function(mcContent:MovieClip)

      {

                trace(mcContent._name);

                trace(mcContent._width);

        loc = ((221 - mcContent._width));

                trace(loc);

      };

       

       

      var myLoader:MovieClipLoader = new MovieClipLoader();

      mcHolder._x=220;

      mcHolder._y=3;

       

       

       

       

      myLoader.loadClip(Pics[0], mcHolder);

      myLoader.addListener(ClipListener);

       

       

       

       

      import mx.transitions.Tween;

      import mx.transitions.easing.*;

       

       

      var tweenOne = new Tween(mcHolder, "_x", Strong.easeOut,220, loc ,3, true);

      tweenOne.onMotionFinished = function (){

      trace(loc);

      }

        • 1. Re: Passing varibles
          Ned Murphy Adobe Community Professional & MVP

          From what I can see of your code, it looks like you need to move the tween inside the onLoadInit function.  Otherwise, it is tweening an empty mcHolder when the code first starts executing and uses an undefined/null loc value to do it.

          • 2. Re: Passing varibles
            JonnyDL Level 1

            Thanks Ned

              That did work. I'm trying to get familular with AS2,

            I had written a simple picture viewer/slider in AS3, but since our new webserver is only accepting as2 clicktags, my as3 code wont work, and I have to rewrite it in AS2, and odly it isn't as easy  as I thought. If you want to take a look and see if you can see what I need to fix, or lead me in a direction that will help. it would be appreciated.

             

            Here is the AS2 code. I'm simply trying to transition one frame to another (pausing for viewer) with tweens based on pics in the array. It appears Im having trouble with the if staements that increase the array indexs choice, and the intrervals between them. I cant seem to see why the counter isnt increasing, and the if statement is not working proberly

             

             

            import mx.transitions.Tween;

            import mx.transitions.easing.*;

            import flash.filters.GlowFilter;

            import flash.filters.DropShadowFilter;

            import flash.filters.BlurFilter;

            import flash.filters.BevelFilter

            /*

            Pics = new Array("Waterfall.jpg","PoolDEck.jpg","Cottage.jpg")

            var ymove:Tween = new Tween(mcHolder, "_y", Strong.easeOut, 3, -50, 3,true);

            TopShelf_mc.swapDepths(4);

            var tweenOne:Tween;

             

             

            this.createEmptyMovieClip("mcHolder", 3);

            var ClipListener:Object = new Object();

            ClipListener.onLoadInit = function(mcContent:MovieClip)

            {

                      trace(mcContent._name);

                      trace(mcContent._width);

                      var loc = ((221 + mcContent._width));

                      tweenOne = new Tween(mcHolder, "_x", Back.easeOut,220, 3, 3, true);

                      tweenOne.onMotionFinished = function (){

                                var ymove:Tween = new Tween(mcHolder, "_y", Back.easeOut, 3, -50, 3,true);

                      xScaleT.onMotionChanged = function (){

                      var xScaleT:Tween = new Tween(mcHolder, "_rotation", Back.easeIn,0, -120, 4, true);

                      }

            }

            };

             

             

            var myLoader:MovieClipLoader = new MovieClipLoader();

            mcHolder._x=220;

            mcHolder._y=3;

             

             

             

             

            myLoader.loadClip(Pics[0], mcHolder);

            myLoader.addListener(ClipListener);

             

            */

             

             

            Pics = new Array("Waterfall.jpg","Pool.jpg","Cottage.jpg")

            var arrayLength:Number

            var arraynum:Number=1;

             

             

            TopShelf_mc.swapDepths(5);

            var slideInLeft:Tween;

            var slideOutLeft:Tween;

            var ClipListener:Object = new Object();

            var myLoader:MovieClipLoader = new MovieClipLoader();

             

             

             

             

            var shadow_distance:Number = 10;

            var shadow_angleInDegrees:Number = 45;

            var shadow_color:Number = 0x000000;

            var shadow_alpha:Number = 0.8;

            var shadow_blurX:Number = 16;

            var shadow_blurY:Number = 16;

            var shadow_strength:Number = 1;

            var shadow_quality:Number = 3;

            var shadow_inner:Boolean = false;

            var shadow_knockout:Boolean = false;

            var shadow_hideObject:Boolean = false;

             

             

            var filter_shadow:DropShadowFilter = new DropShadowFilter(shadow_distance, shadow_angleInDegrees, shadow_color, shadow_alpha, shadow_blurX, shadow_blurY, shadow_strength, shadow_quality, shadow_inner, shadow_knockout, shadow_hideObject);

             

             

            this.createEmptyMovieClip("mcHolderOne", 3);

            mcHolderOne._x=0;

            mcHolderOne._y=0;

             

            myLoader.loadClip(Pics[0], mcHolderOne);

            myLoader.addListener(ClipListener);

             

            var timerstart:Number = setInterval(pauseOne, 4000);

             

            if(Pics.length>1)

            {

                      this.createEmptyMovieClip("mcHolderTwo", 4);

                      myLoader.loadClip(Pics[arraynum], mcHolderTwo);

                      mcHolderTwo._x=221;

                      mcHolderTwo._y=0;

             

            };

             

            ClipListener.onLoadInit = function(mcContent:MovieClip)

            {

            }

             

             

            function pauseOne():Void

            {

                      clearInterval(timerstart);

                      clearInterval(timerOne);

                      slideOutLeft = new Tween(mcHolderOne, "_x", Strong.easeOut, 0, -(mcHolderOne._width+2), 3,true);

                      slideInLeft = new Tween(mcHolderTwo, "_x", Strong.easeIn, 221, 0, 3,true);

             

                      slideOutLeft.onMotionFinished = function ():Void

                      {

                                mcHolderOne._x=221;

                                arraynum=arraynum+1;

                                trace(arraynum);

                                trace(Pics.length);

                                if(arraynum != Pics.length);

                                {

                                          trace("changed");

                                          arraynum=0;

                                }

                                mcHolderOne._x=221;

                                var timerTwo:Number = setInterval(pauseTwo, 4000);

             

             

            }

            }

             

             

            function pauseTwo():Void

            {

                      clearInterval(timerTwo);

                      myLoader.loadClip(Pics[arraynum], mcHolderOne);

                      slideOutLeft = new Tween(mcHolderTwo, "_x", Strong.easeOut, 0, -(mcHolderTwo._width+2), 3,true);

                      slideInLeft = new Tween(mcHolderOne, "_x", Strong.easeIn, 221, 0, 3,true);

             

             

            }

            slideOutLeft.onMotionFinished = function ():Void

                      {

                                mcHolderTwo._x=221;

                                arraynum=arraynum+1;

                                trace(arraynum);

                                trace(Pics.length);

                                if(arraynum != Pics.length);

                                {

                                          trace("changed");

                                          arraynum=0;

                                }

                                mcHolderTwo._x=221;

                                var timerOne:Number = setInterval(pauseOne, 4000);

            }