PDA

View Full Version : How to Propagate Tweener to Children?


adsforjon
07-19-2009, 05:20 AM
Does anyone know how to propagate tweener mouse events only to the children of a movieclip? I have an mc with small thumbnail images inside that are also mcs. I'd like to scale them up with tweener, but I don't want to have to add a listener for every thumb (there are 50 of them). Propagating sounds like the way to go, but I'm having trouble.

Here's my code:

// Listen for scrollPanel function
stage.addEventListener(Event.ENTER_FRAME, scrollPanel);

// Function that controls scrolling
function scrollPanel(event:Event):void {
// Scrolling speed
var slowness=15;
// Area in which no scrolling occurs
var buffer=150;

// Acceleration: get the absolute value of
// the mouse's x-coordinates relative to the
// stage center, and subtract it by the buffer
var xdist=Math.abs(mouseX-478.5)-buffer;
// Exectute if the value is positive (not in the buffer zone)
if (xdist<0) {
return;
}
// Positive or negative
var sign=-1;
// Make sign positive if the mouse is to the left of center
if (mouseX<478.5) {
sign=1;
}
// Animate timeline
timeline_mc.x += sign*(xdist / slowness);
// Stop when timeline is at the beginning
if (timeline_mc.x>=43.8) {
timeline_mc.x=43.8;
}
// Stop when timeline is at the end
if (timeline_mc.x<=-4180.4) {
timeline_mc.x=-4180.4;
}
}

// Animation

import caurina.transitions.Tweener;

timeline_mc.addEventListener(MouseEvent.MOUSE_OVER , onOver);
timeline_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut);

function onOver(evt:MouseEvent):void {
Tweener.addTween(timeline_mc, {scaleX:1.2, scaleY: 1.2, time: 2, transition:"easeOut"});
}

function onOut(evt:MouseEvent):void {
Tweener.addTween(timeline_mc, {scaleX:1, scaleY: 1, time: 2, transition:"easeOut"});
}

//function onOver(evt:MouseEvent):void {
// evt.target.scaleX=1.2;
// evt.target.scaleY=1.2;
//}

//function onOut(evt:MouseEvent):void {
// evt.target.scaleX=1;
// evt.target.scaleY=1;
//}

timeline_mc.mouseChildren=true;
timeline_mc.mouseEnabled=false;

Mazoonist
07-19-2009, 08:05 AM
Inside your event handlers, just use evt.target as the object for tweener to act upon. For example:
function onOver(evt:MouseEvent):void {
Tweener.addTween(evt.target, {scaleX:1.2, scaleY: 1.2, time: 2, transition:"easeOut"});
}
Then, even though you added just one listener to the container, the container's children will respond to the event as well. http://theflashconnection.com/content/understanding-as3-event-flow

adsforjon
07-24-2009, 07:54 AM
Thanks Mazoonist, that's exactly what I needed. Sorry for being so new at this.