?
Solved

AS3 scale and alpha tweening

Posted on 2010-08-17
5
Medium Priority
?
956 Views
Last Modified: 2013-11-11
Hi all, I have this file working just as I want it, except there's one annoying little problem. When you move the mouse over the lettering in one of the boxes then move your mouse away it appears again! http://www.andrewsaldridgehost.com/error/flashMapAS3Test.swf - The FLA is here: http://www.andrewsaldridgehost.com/error/flashMapAS3Test.fla and here's the code:
import fl.transitions.Tween; 
import fl.transitions.TweenEvent; 
import fl.transitions.easing.*; 
import flash.events.* 

button_mc.addEventListener(MouseEvent.MOUSE_OVER, grow) 
button_mc.addEventListener(MouseEvent.MOUSE_OUT, shrink)
button_2_mc.addEventListener(MouseEvent.MOUSE_OVER, grow)
button_2_mc.addEventListener(MouseEvent.MOUSE_OUT, shrink)

function grow(e:MouseEvent):void { 
    
	var sX:Tween = new Tween(e.currentTarget, "scaleX", Regular.easeOut, e.currentTarget.scaleX, 1.5, 0.5, true) 
    var sY:Tween = new Tween(e.currentTarget, "scaleY", Regular.easeOut, e.currentTarget.scaleY, 1.5, 0.5, true)
	var area:Tween = new Tween(e.currentTarget.getChildAt(1),"alpha",Regular.easeInOut,e.currentTarget.getChildAt(1).alpha,1,.4,true);
	
} 

function shrink(e:MouseEvent):void { 
     
    var sX:Tween = new Tween(e.currentTarget, "scaleX", Regular.easeOut, e.currentTarget.scaleX, 1, 0.5, true) 
    var sY:Tween = new Tween(e.currentTarget, "scaleY", Regular.easeOut, e.currentTarget.scaleY, 1, 0.5, true)
	var area:Tween = new Tween(e.currentTarget.getChildAt(1),"alpha",Regular.easeInOut,e.currentTarget.getChildAt(1).alpha,0,.2,true);
	
} 

Open in new window

Many thanks :]
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Assisted Solution

by:edchipman
edchipman earned 400 total points
ID: 33456641
Looks like the mouse over event is being called when its shrinking as well, one way to stop this would be to remove the event listeners on that button when its in transition. See the code snippit for how to do this.

import fl.transitions.Tween; 
import fl.transitions.TweenEvent; 
import fl.transitions.easing.*; 
import flash.events.* 

button_mc.addEventListener(MouseEvent.MOUSE_OVER, grow) 
button_mc.addEventListener(MouseEvent.MOUSE_OUT, shrink)
button_2_mc.addEventListener(MouseEvent.MOUSE_OVER, grow)
button_2_mc.addEventListener(MouseEvent.MOUSE_OUT, shrink)

function grow(e:MouseEvent):void { 
    //Remove listeners
	e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, grow);
	e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, shrink);
	
	
	var sX:Tween = new Tween(e.currentTarget, "scaleX", Regular.easeOut, e.currentTarget.scaleX, 1.5, 0.5, true) 
    var sY:Tween = new Tween(e.currentTarget, "scaleY", Regular.easeOut, e.currentTarget.scaleY, 1.5, 0.5, true)
	var area:Tween = new Tween(e.currentTarget.getChildAt(1),"alpha",Regular.easeInOut,e.currentTarget.getChildAt(1).alpha,1,.4,true);
	
	//using sX as a target as it an sY are the longest tweens
	sX.addEventListener(TweenEvent.MOTION_FINISH, enableListeners);
} 

function shrink(e:MouseEvent):void { 
    //Remove listeners
	e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, grow);
	e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, shrink);
     
    var sX:Tween = new Tween(e.currentTarget, "scaleX", Regular.easeOut, e.currentTarget.scaleX, 1, 0.5, true) 
    var sY:Tween = new Tween(e.currentTarget, "scaleY", Regular.easeOut, e.currentTarget.scaleY, 1, 0.5, true)
	var area:Tween = new Tween(e.currentTarget.getChildAt(1),"alpha",Regular.easeInOut,e.currentTarget.getChildAt(1).alpha,0,.2,true);
	
	//using sx as a target as it an sy are the longest tweens
	sX.addEventListener(TweenEvent.MOTION_FINISH, enableListeners);
}

function enableListeners(e:TweenEvent):void {
	//Clean up
	e.currentTarget.removeEventListener(TweenEvent.MOTION_FINISH, enableListeners);
	
	
	//Redefine Listeners based on the tween's target
	e.currentTarget.obj.addEventListener(MouseEvent.MOUSE_OVER, grow);
	e.currentTarget.obj.addEventListener(MouseEvent.MOUSE_OUT, shrink);
}

Open in new window

0
 
LVL 5

Expert Comment

by:edchipman
ID: 33456701
Oh and tweens have this nasty habbit of being cleaned up by the garbage collector before they complete, the trick to fixing this is to apply a listener to them then remove that listener when it completes. Have a look at http://www.flashmorgan.com/index.php/2007/11/18/as3-garbage-collection-the-reason-your-tweens-are-ending-early/ for more information on that issue :).
0
 
LVL 5

Assisted Solution

by:truromeo4juliet
truromeo4juliet earned 400 total points
ID: 33456773
you need to incorporate an if statement to check a variable to see if the object is currently on the screen, and only run the tweek if it's visible... otherwise, flash will restart from the original variables of the clips you're modifying. I could give the exact code you may need, but I'm not at home right now, sorry. :(
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 1200 total points
ID: 33456964
Hi, you're the second one this week.
you need to set the mouseChildren properties to false

button_mc.mouseChildren = false;
button_2.mouseChildren = false;

the thing is the mc inside is triggering the mouse over etc as well
0
 

Author Comment

by:wheelsfalloffbandwagons
ID: 33462466
Thanks Blue Genie, I thought as much! When I didn't move the mouse over the text it was okay!!! Thanks for the other assistance though, it gave me a good insight into what I was doing :] Points for all!
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question