8 Replies Latest reply on Dec 2, 2009 7:02 AM by Ned Murphy

    onRelease and onPress problem

    darkprince010

      Hi

      Not speak very good English.

      I hold the picture in the gallery picture is growing.Leave when declining.When I click on the image I want to grow.When I want to shrink again.I could not do.

      Can you help me on this issue?

        • 1. Re: onRelease and onPress problem
          Ned Murphy Adobe Community Professional & MVP

          Yes, it is hard to be sure of what you ask for, but see if the attached file does what you want...

          1 person found this helpful
          • 2. Re: onRelease and onPress problem
            Rothrock Level 5

            My guess is that you don't have an onReleaseOutside event handler declared and that in the growing and shrinking that the hit area has moved off the pointer.

             

            If you have something like this:

             

             

            myClip.onRelease=someFunction

             

            function someFunction(){

            //shrinking code

            //whatever else

            }

             

            You can change the line to:

             

            myClip.onRlease=myClip.onReleaseOutside=someFunction

            • 3. Re: onRelease and onPress problem
              darkprince010 Level 1

              Hello again,

              I know my English isn't good and asked for my friend for help to translate my question.


              I am making a picture gallery using flash actionscript. And i have a

              problem on my algorithm. I just want to toggle gallery pictures' size

              between full sized and thumbnails with mouse clicks.
              I've attached my code, any ideas on how to do this?


              Hope i could explain my question

              Thanks for all your help.

              • 4. Re: onRelease and onPress problem
                Ned Murphy Adobe Community Professional & MVP

                What you need to do in this case is to have a variable that you use to keep track of the current state of the object so that when you click it a decision is made based on that variable.  You then combine your onPress and onRelease functions into that decision process.  If you replace your onLoadInit function with the following that's what it does.  It uses a variable named "small" to decide whether to expand or contract the image...  see the red code...

                 

                // when the onLoadInit event is thrown, you're free to position the instances
                mclListener.onLoadInit = function(evt:MovieClip) {
                evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
                /* set local variables for the target movie clip's width and height,
                    and the desired settings for the image stroke and border. */
                var thisWidth:Number = evt._width;
                var thisHeight:Number = evt._height;
                var borderWidth:Number = 2;
                var marginWidth:Number = 8;

                evt.small = true;

                evt.scale = 20;
                // draw a white rectangle with a black stroke around the images.
                evt.lineStyle(borderWidth, 0x000000, 100);
                evt.beginFill(0xFFFFFF, 100);
                evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
                evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
                evt.lineTo(thisWidth+borderWidth+marginWidth, thisHeight+borderWidth+marginWidth);
                evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
                evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
                evt.endFill();

                /* scale the target movie clip so it appears as a thumbnail.
                    This allows users to quickly view a full image without downloading it every time,
                    but unfortunaltey also causes a large initial download. */
                evt._xscale = evt.scale;
                evt._yscale = evt.scale;
                // rotate the current image (and borders) anywyhere from -5 degrees to +5 degrees.
                evt._rotation = Math.round(Math.random()*-10)+5;
                /* when the target_mc movie clip instance is pressed, begin to drag the current movie clip
                    and set some temporary variables so once you are finished rescaling and positioning
                    the full image, you can return the instance to its original position. */
                evt.onRelease = function() {
                  if(this.small){
                   this.small = false;
                   /* set the _xscale and _yscale properties back to 100% so the image appears full sized.
                      You're also storing the original X and Y coordinates so you can return the image where you found it. */
                   this.origX = this._x;
                   this.origY = this._y;
                   var xtw = new Tween(this, "_xscale", Regular.easeIn, this._xscale, 100, .5, true);
                   var ytw = new Tween(this, "_yscale", Regular.easeIn, this._yscale, 100, .5, true);
                   var xxtw = new Tween(this, "_x", Regular.easeIn, this._x, 100, .5, true);
                   var yytw = new Tween(this, "_y", Regular.easeIn, this._y, 75, .5, true);

                  
                   // find the depth of the current movie clip, and store it within the movie clip.
                   this.origDepth = this.getDepth();
                   /* :TRICKY: swap the depth of the current movie clip, with the next highest movie clip of the _parent.
                      Effectively this makes the current movie clip the top of the "stack". */
                   this.swapDepths(this._parent.getNextHighestDepth());
                   // try and center the current movie clip on the Stage.
                   this._x = (_global.stageWidth-evt._width+30)/2;
                   this._y = (_global.stageHeight-evt._height+30)/2;
                   // apply a transition to the movie clip which makes the movie clip flicker for a split second.
                   mx.transitions.TransitionManager.start(this, {type:mx.transitions.Photo, direction:0, duration:1, easing:mx.transitions.easing.Strong.easeOut, param1:empty, param2:empty});
                  } else {
                   this.small = true;
                   var xtw = new Tween(this, "_xscale", Regular.easeIn, this._xscale, 20, .5, true);
                   var ytw = new Tween(this, "_yscale", Regular.easeIn, this._yscale, 20, .5, true);
                   var xxtw = new Tween(this, "_x", Regular.easeIn, this._x, this.origX, .5, true);
                   var yytw = new Tween(this, "_y", Regular.easeIn, this._y, this.origY, .5, true);
                  }
                };
                };

                 

                The drawback to doing this is that you can click on other images that lie in the background and they also expand.  That is why your original design works better in this regard beauce as soon as you release an image to click another, the one currently expanded will contract.

                1 person found this helpful
                • 5. Re: onRelease and onPress problem
                  darkprince010 Level 1

                  Excuse me:S

                  I couldn't do.Can you upload .fla file?

                  Thanks for your helps.

                  • 6. Re: onRelease and onPress problem
                    Ned Murphy Adobe Community Professional & MVP

                    Here is an fla using that code...

                    • 7. Re: onRelease and onPress problem
                      darkprince010 Level 1

                      Thanks for all

                      • 8. Re: onRelease and onPress problem
                        Ned Murphy Adobe Community Professional & MVP

                        You're welcome