PDA

View Full Version : AS3 TweenLite/Mouseover/Math.Random Help!!



GuitarPlaya4JC
September 21st, 2008, 12:32 PM
import gs.TweenLite;
import gs.OverwriteManager;
import gs.easing.*;

stop();

OverwriteManager.init();

var clipArray:Array = new Array();

var numButtons:int = 31;
for (var k:int = 1; k < numButtons; k++)
{
this["btn" + k].addEventListener(MouseEvent.CLICK, showClickedImage);
//push each button into an array
clipArray.push(this["btn"+k]);
}



function openRandomClip():void
{
var randomClip:int = Math.random()*clipArray.length;
showClickedImage(null, clipArray[randomClip]);
}


openRandomClip();


function showClickedImage(event:MouseEvent = null, targetClip:SimpleButton = null):void
{
var target:Object = event!=null ? event.target : targetClip;
//cary on as normal
this.setChildIndex(this.getChildByName(target.name ), this.numChildren-1);
var orgWidth:int = target.width;
var orgHeight:int = target.height;
var orgX:int = target.x
var orgY:int = target.y
TweenLite.to(target, 1, {width:350, height:350, x:25, y:0, ease:Bounce.easeOut, delay: 1})
TweenLite.to(target, 1, {width:orgWidth, height:orgHeight, x:orgX, y:orgY, ease:Bounce.easeOut, delay:4})
}
This is my code that make myimage thumbnails tween to maximized stage size than tween back again a few seconds after. I'm wondering if someone could help me make the openRandomClip function get called again or loop somehow so that the images will continue to randomly maximize then shrink on their own. I used the onComplete arguement to do this at first, but then the dilemna exists where I want the user to be able to click on any of the thumbnails and have only that specific image maximize. I had that working, but it wouldn't stop the openRandomClip when the user clicks, so two images would then start popping up, and everytime you click a thumbnail another randomimage routine would be added to the mix.

I basically just want to be able to make it so that when/if the user mouses over ANY thumbnail it will just pause the openRandomClip from happening and let the user look around and click certain ones if desired. Then once the user mouses out off the entire movie of just off all the thumbnails I want the randomclip to resume again.


Can anyone help me with that? I'm totally stuck on how to do it!! Thanks in advance!

-Matt :)

pensamente
September 21st, 2008, 06:36 PM
hey there,
hope this helps.... go and check if it does... if not you know you can come back ;P

var userInactive:Boolean = false;
var intervalId:uint = intervalId = setInterval(openRandomClip, 3000);;

var inactiveTime:int = 3000;
var t:Timer = new Timer(inactiveTime);

stage.addEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
t.addEventListener(TimerEvent.TIMER, onTimer);
t.start();


///// your function
function openRandomClip():void
{
if (userInactive)
{
var randomClip:int = Math.random()*clipArray.length;
showClickedImage(null, clipArray[randomClip]);
} else {
trace('stop loop')
}
}

///// detect inactivity functions
function MouseMove(e:MouseEvent):void
{
//clearInterval(intervalId);
userInactive = false;
t.reset();
t.start();
}
function onTimer(e:TimerEvent):void
{
userInactive = true;
}

GuitarPlaya4JC
September 22nd, 2008, 02:41 PM
Well, I think we're getting closer...I'm NOT sure what your code does exactly, so I'm not sure how to adapt it to do exactly what I want. I guess I'll just explain to you and see what you think....So I replace my openRandomClip function with all the code you gave me. When I preview the movie it spits out "stop loop" "stop loop" twice right at the beginning. If I mouse over the thumbnails it pauses for a second and spits out "stop loop" twice again but then starts the automated tweening before I ever mouse out. It also doesn't have any delay anymore from tween to tween. As one image is shrinking, the next thumbnail is already maximizing/tweening out. Any thoughts here? Thanks!

GuitarPlaya4JC
October 16th, 2008, 08:33 PM
Does anybody have any ideas on how to get it to tween like this and still have the mouseover effects I want it to!?? I'm still waiting hoping that somebody has some more ideas for me!

Thanks in advance,
Matt