Copy link to clipboard
Copied
Hey folks,
With some great help I have my movieclip dragging. Now I have a set of content bands in that long movieclip that I'd like to play with. So for example in a child movieclip I have an arrow that I'd like to trigger it's jump to it's second keyframe. Seems simple enough. But I think the listener for the parent drag is overriding it's ability to change or get recognized. I went with the mouse down listener for the drag and the mouseclick for the button tap. Still doesn't kick. Logically I can't see why. Ideas? Have the areas bolded. Really simple stuff in theory
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.geom.Rectangle;
import flash.utils.getTimer;
import flash.events.MouseEvent;
import flash.text.*;
import flash.display.*;
TweenPlugin.activate([ThrowPropsPlugin]);
main.bandfourarrow.addEventListener(MouseEvent.CLICK, ofbandsevenbutton);
var bounds:Rectangle = new Rectangle(0, 0, 1280.15, 720);
var blitMask:BlitMask = new BlitMask(main, bounds.x, bounds.y, bounds.width, bounds.height, false);
var t1:uint, t2:uint, y1:Number, y2:Number, yOverlap:Number, yOffset:Number;
blitMask.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
TweenLite.killTweensOf(main);
y1 = y2 = main.y;
yOffset = this.mouseY - main.y;
yOverlap = Math.max(0, main.height - bounds.height);
t1 = t2 = getTimer();
main.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
main.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
function mouseMoveHandler(event:MouseEvent):void {
var y:Number = this.mouseY - yOffset;
//if main's position exceeds the bounds, make it drag only half as far with each mouse movement (like iPhone/iPad behavior)
if (y > bounds.top) {
main.y = (y + bounds.top) * 0.5;
} else if (y < bounds.top - yOverlap) {
main.y = (y + bounds.top - yOverlap) * 0.5;
} else {
main.y = y;
}
blitMask.update();
var t:uint = getTimer();
//if the frame rate is too high, we won't be able to track the velocity as well, so only update the values 20 times per second
if (t - t2 > 50) {
y2 = y1;
t2 = t1;
y1 = main.y;
t1 = t;
}
event.updateAfterEvent();
}
function mouseUpHandler(event:MouseEvent):void {
main.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
main.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
var time:Number = (getTimer() - t2) / 1000;
var yVelocity:Number = (main.y - y2) / time;
ThrowPropsPlugin.to(main, {throwProps:{
y:{velocity:yVelocity, max:bounds.top, min:bounds.top - yOverlap, resistance:50}
}, onUpdate:blitMask.update, ease:Strong.easeOut
}, 2, 0.3, 0.5);
}
function ofbandsevenbutton(e: MouseEvent): void
{
main.bandfourarrow.gotoAndStop(2);
}
Copy link to clipboard
Copied
enable the capture parameter of your listener (and you may want to stop that events propagation in the listener function).
main.bandfourarrow.addEventListener(MouseEvent.CLICK, ofbandsevenbutton,true);
function ofbandsevenbutton(e:MouseEvent):void{
e.stopImmediatePropagation();
.
.
.
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now