I'm trying to make an easter egg in my AS3 app, that appears when the user hovers their cursor over a seperate trigger, and disappears when they stop hovering over it.
var hideEast:Tween=new Tween(easter_mc,"alpha",null,100,0,1,false);
easterTrigger_btn.addEventListener(MouseEvent.MOUSE_OVER, triEas);
easterTrigger_btn.addEventListener(MouseEvent.MOUSE_OUT, remEas);
function triEas (e:MouseEvent):void{
var showEast:Tween=new Tween(easter_mc,"alpha",null,0,100,1,false);
}
function remEas (e:MouseEvent):void{
var hideEast;
}
This is the code I've tried to use. It shows the movie clip when the trigger is being hovered over, but the movie clip stays when the triggered isn't being hovered over anymore.
Because you don't have any animation in your MOUSE_OUT handler.
Also, I would recommend tweening engine from Jack Doyle - TweenLite.
trigger.addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
trigger.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
function onOver(e:MouseEvent):void {
TweenLite.to(trigger, 0.3, {alpha: 1, ease: Sine.easeOut});
}
function onOut(e:MouseEvent):void {
TweenLite.to(trigger, 0.5, {alpha: 0, ease: Sine.easeInOut});
}
Or you can go further and use visibility.
trigger.alpha = 0;
trigger.visible = false;
TweenPlugin.activate([AutoAlphaPlugin]);
trigger.addEventListener(MouseEvent.MOUSE_OVER, onOver, false, 0, true);
trigger.addEventListener(MouseEvent.MOUSE_OUT, onOut, false, 0, true);
function onOver(e:MouseEvent):void {
TweenLite.to(trigger, 0.3, {autoAlpha: 1, ease: Sine.easeOut});
}
function onOut(e:MouseEvent):void {
TweenLite.to(trigger, 0.5, {autoAlpha: 0, ease: Sine.easeInOut});
}
Related
I am having a problem with a series of drop down menus i'm trying to make. I have 3 buttons, each of which when hovered over, drops down a sub menu with options. The problem I'm running into is that the first menu works, it drops down as it should. The second and third menus however do not work, and I don't understand why. I'm not getting an error code, and some googling directed me to people who were having similar problems suggesting flash garbage collection might be what is causing my issue. i'm not sure how to structure it so that this wont happen. I should also add that this is my first time posting so I apologize for any format issues in the post, and I'm very new to coding so any help will be much appreciated, I don't really know the questions to ask to get me going in the right direction.
Thankyou for your time
The code I have so far is as follows
import fl.transitions.Tween;
import fl.transitions.easing.Regular;
stop();
menu_cont.paint_rect.alpha = 0;
menu_cont.trim_rect.alpha = 0;
menu_cont.wheels_rect.alpha = 0;
menu_cont.paint_btn.addEventListener(MouseEvent.ROLL_OVER, paintRollOver);
menu_cont.paint_rect.addEventListener(MouseEvent.MOUSE_OUT, paintMouseOut);
menu_cont.trim_btn.addEventListener(MouseEvent.ROLL_OVER, trimRollOver);
menu_cont.trim_rect.addEventListener(MouseEvent.MOUSE_OUT, trimMouseOut);
menu_cont.wheels_btn.addEventListener(MouseEvent.ROLL_OVER, wheelsRollOver);
menu_cont.wheels_rect.addEventListener(MouseEvent.MOUSE_OUT, wheelsMouseOut);
var paintMenuTween:Tween = new Tween (menu_cont.paint_menu, "y",
Regular.easeOut,menu_cont.paint_menu.y, 50, .5, true);
var paintMenuTween2:Tween = new Tween (menu_cont.paint_menu, "y",
Regular.easeOut,menu_cont.paint_menu.y, -15, .5, true);
var trimMenuTween:Tween = new Tween (menu_cont.trim_menu, "y",
Regular.easeOut,menu_cont.trim_menu.y, 50, .5, true);
var trimMenuTween2:Tween = new Tween (menu_cont.trim_menu, "y",
Regular.easeOut,menu_cont.trim_menu.y, -15, .5, true);
var wheelsMenuTween:Tween = new Tween (menu_cont.wheels_menu, "y",
Regular.easeOut,menu_cont.wheels_menu.y, 50, .5, true);
var wheelsMenuTween2:Tween = new Tween (menu_cont.wheels_menu, "y",
Regular.easeOut,menu_cont.wheels_menu.y, -15, .5, true);
function paintRollOver (event:MouseEvent):void {
paintMenuTween = new Tween (menu_cont.paint_menu, "y",
Regular.easeOut,menu_cont.paint_menu.y, 50, .5, true);
trace ("paint over")
}
function paintMouseOut (event:MouseEvent):void {
paintMenuTween2 = new Tween (menu_cont.paint_menu, "y",
Regular.easeOut,menu_cont.paint_menu.y, -15, .5, true);
trace ("paint out")
}
function trimRollOver (event:MouseEvent):void {
trimMenuTween = new Tween (menu_cont.trim_menu, "y", Regular.easeOut,menu_cont.trim_menu.y, 50, .5, true);
trace("trim over")
}
function trimMouseOut (event:MouseEvent):void {
trimMenuTween2 = new Tween (menu_cont.trim_menu, "y", Regular.easeOut,menu_cont.trim_menu.y, -15, .5, true);
trace("trim out")
}
function wheelsRollOver (event:MouseEvent):void {
wheelsMenuTween = new Tween (menu_cont.wheels_menu, "y", Regular.easeOut,menu_cont.wheels_menu.y, 50, .5, true);
trace ("wheels over")
}
function wheelsMouseOut (event:MouseEvent):void {
wheelsMenuTween2 = new Tween (menu_cont.wheels_menu, "y", Regular.easeOut,menu_cont.wheels_menu.y, -15, .5, true);
trace ("wheels out")
}
I'm trying to create a simple slideshow of 3 images going from left to right.
I want to check if the last image is on stage ( so the image3.x = 0 ) in order to start the new Tween.
I thought it would be something a simple as the following code, but that doesn't seem to work.
function Start() {
if(image3.x == 0){
var myTween:Tween = new Tween(image, "x", None.easeNone, -140, 640, 10, true);
}
}
stage.addEventListener(Event.ENTER_FRAME, Start);
Split the original Tween in two parts, from -140 to 0 and from 0 to 640.
var tween:Tween = new Tween(image, "x", None.easeNone, -140, 0, 10, true);
Wait for it to finish:
tween.addEventListener(TweenEvent.MOTION_FINISH, onZeroReached);
Then do the second part plus whatever else you want to do:
function onZeroReached(te:TweenEvent):void
{
tween = new Tween(image, "x", None.easeNone, 0, 640, 10, true);
// do additional stuff here
}
code untested
I am panning a background but I can not pan Movie Clips that are on that background is there anyway I can pan multiple Movie Clips? Currently I have somthing that looks like this
panning a single Movie Clip how can I pan multiple Movie Clips?
world.addEventListener(MouseEvent.MOUSE_DOWN, beginPan, false, 0, true);
function beginPan(e:MouseEvent):void
{
deltaX = mouseX - world.x;
deltaY = mouseY - world.y;
addEventListener(Event.ENTER_FRAME, doPan, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, endPan, false, 0, true);
}
function doPan(e:Event):void
{
var curX:int = mouseX - deltaX;
var curY:int = mouseY - deltaY;
world.x = curX;
world.y = curY;
}
function endPan(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, endPan);
removeEventListener(Event.ENTER_FRAME, doPan);
}
For the life of me I can't remember how to make a sprite respond to MOUSE_DOWN and MOUSE_UP...works if I link the listener to the stage but not a sprite...What am I doing wrong?
private function allClassesReady(e:Event):void
{
userName00 = e.currentTarget.userName0;
chatArea00 = e.currentTarget.ui0.chatArea0;
chatInput00 = e.currentTarget.ui0.chatInput0;
btnArr00 = e.currentTarget.ui0.btnArr0;
userList00 = e.currentTarget.ui0.userList0;
msgSo00 = e.currentTarget.shaob0.msgSo0;
userListSo00 = e.currentTarget.shaob0.userListSo0;
main00.stage.addEventListener(KeyboardEvent.KEY_DOWN, displayKey);
main00.stage.addEventListener(MouseEvent.MOUSE_WHEEL, scrollsTxtArea, false, 0, true);
/*listens for the enter key on the keyboard so we can send message when pressed*/
btnArr00[0].addEventListener(MouseEvent.MOUSE_DOWN, sendMsg, false, 0, true);
btnArr00[0].addEventListener(MouseEvent.MOUSE_UP, sendBtnRelease, false, 0, true);
}
I'm trying to remove a tween object after it has complete so the memory can be freed by garbage collection.
In this example I'm passing the fadeIn function a UILoader object that is cast as a sprite so that it fades in when it is finished loading. When the tween finishes animating, I want to remove the tween object. I've included the compiler errors as comments.
function fadeIn(e:Sprite):void
{
var myTween:Tween = new Tween(e, "alpha", None.easeNone, 0.0, 1.0, 0.2, true);
myTween.addEventListener(Event.COMPLETE, deallocateObject, false, 0, true);
}
function deallocateObject(e:Event):void
{
//delete(e.currentTarget); //Warning: 3600: The declared property currentTarget cannot be deleted. To free associated memory, set its value to null.
e.currentTarget = null; //1059:Property is read-only.
}
First of all, you want to use a TweenEvent to handle the completion of the tween. The currentTarget property of Event is read-only, so you need to "get" the current target from the event and cast it as a tween, then remove your event and set it to null:
// assuming MC on stage with instance name "test"
import fl.transitions.*;
import fl.transitions.easing.*;
function fadeIn(e:Sprite):void
{
var myTween:Tween = new Tween(e, "alpha", None.easeNone, 0.0, 1.0, 1, true);
myTween.addEventListener(TweenEvent.MOTION_FINISH, deallocateObject, false, 0, true);
}
function deallocateObject(e:TweenEvent):void
{
var myTween:Tween = e.currentTarget as Tween;
// -- I always remove even when using weak listeners
myTween.removeEventListener(TweenEvent.MOTION_FINISH, deallocateObject);
myTween = null;
}
fadeIn(test);
Watch out when using local Tweens inside a function. Often they will get garbage collected before the tween completes. You'll have to declare the tween as a class property instead if that happens. I recommend saving yourself some headache and using Tweener, gTween, et al. The Tween class sucks.
function fadeIn(e:Sprite):void
{
var myTween:Tween = new Tween(e, "alpha", None.easeNone, 0.0, 1.0, 0.2, true);
myTween.addEventListener(TweenEvent.MOTION_FINISH, deallocateObject);
}
function deallocateObject(e:Event):void
{
delete(e.currentTarget as Tween);
}
This works.