Skip to main content
Participant
June 18, 2009
Question

Newbie - There has to be an easier way to enlarge a mc and shrink mc on click

  • June 18, 2009
  • 2 replies
  • 776 views

First off I'm a newbie, so sorry -

What I am trying to do is make a image enlarge on click and then click it to go back to the original size. I am using TweenLite to achieve this. I am thinking that AS 3.0 code would be easier to do this. I tried it but was coming up with no error it only worked one time. So I was able to get it to work, sort of. Right now, it eases larger but when clicked again it jumps back down to the original size (no easing). I am not asking for you to do the code, unless you want to, I just was wondering if anyone knows where I could research it. I am new to AS 3.0 so forgive me. But, there has to be code for this.

Any help is greatly appreciated. File is attached if you want to see how a newbie can butcher a file.

I am using Flash CS4 ActionScript 3.0

This topic has been closed for replies.

2 replies

Participant
December 3, 2009

This code works for scaling the images using TweenLite and an external ActionScript 3.0 file - you could always use this code on the timeline also. You can see I have set up a class called ImageContainer - substitute your class for that. That is also called in the public function so be sure to change that. I called the instance name of the image I wanted to scale - you will need to substitute there also. Not sure about how it will play with your background.

package {

import flash.display.Sprite;

import flash.display.MovieClip;

import flash.display.StageScaleMode;

import flash.events.Event;

import flash.events.MouseEvent;

import com.greensock.*;

import com.greensock.easing.*;

public class imageContainer extends MovieClip {

private var tween1:TweenLite;

private var tween2:TweenLite;

public function imageContainer() {

instance name.addEventListener(MouseEvent.ROLL_OVER, scaleIt1);

instance name.addEventListener(MouseEvent.ROLL_OUT, scaleIt2);

}

private function scaleIt1(event:MouseEvent):void{

tween1 = new TweenLite(instance name, 1, {scaleX:1.5, scaleY:1.5});

   }

private function scaleIt2(event:MouseEvent):void{

tween2 = new TweenLite(instance name, 1, {scaleX:1, scaleY:1});

   }

}

}

Ned Murphy
Legend
June 18, 2009

If you can show the code you are using, someone may be able to see why it might not be downsizing with easing.  I am not familiar with using tweenlite, so I'll be partially challenged to reconcile it, but someone else may be able to see the Lite if I can't.

Participant
June 18, 2009

Here is the code for the first frame.

stop();
import flash.events.MouseEvent;
import flash.net.URLRequest;
import gs.TweenLite;
import fl.transitions.*;
import fl.transitions.easing.*;
TweenLite.to(p17_mc, .5, {x:275.2, y:349.4, scaleX:1, scaleY:1});
TweenLite.to(black_mc, 0, {autoAlpha:0});
function main(event:MouseEvent):void {
MovieClip(root).gotoAndPlay("first");
trace ("something good just happened!");
}
p17_mc.addEventListener(MouseEvent.CLICK, main);

Code for the Second Frame.

stop();
import gs.TweenLite;
TweenLite.to(p17b_mc, 1, {x:250, y:100, scaleX:5, scaleY:5});
TransitionManager.start(blackb_mc, {type:Fade, direction:Transition.IN, duration:4, easing:Strong.easeOut});
function home(event:MouseEvent):void {
MovieClip(root).gotoAndPlay("firstfadeout");
trace ("going to fade out");
}
p17b_mc.addEventListener(MouseEvent.CLICK, home);

Code for the Third Frame.

TweenLite.to(p17b_mc, .5, {x:275.2, y:349.4, scaleX:1, scaleY:1});
TransitionManager.start(blackb_mc, {type:Fade, direction:Transition.OUT, duration:4, easing:Strong.easeIn});
gotoAndPlay("home");
trace ("going home");
Thanks

Ned Murphy
Legend
June 18, 2009

Is there a reason for changing frames?  What frames are represented by the labels you use in your gotoAndPlay code?