8 Replies - 3941 Views - Last Post: 06 November 2009 - 05:23 AM

#1 amitbiswas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-October 09

Randomly fade in and fade out animation issue!

Post icon  Posted 02 November 2009 - 01:41 PM

Hello friends,

I am new in AS3. Still learning. I have a bunch of MovieClips in my first keyframe. And I want to animate it randomly. I mean the movieclips should be fadein and fadeout randomly. the duration of Fade-in and Fadeout should be same for each MovieClips. Here I am stuck in a section. I have successfully completed Fade-in for each MC. But I do not understand what to do next! If anyone could give me some clue or help me, it will be great for me. here is the code I wrote.

Thanks
Amit

//Flash Makes that tween
import fl.transitions.Tween;
import fl.transitions.easing.*;

var myClips:Array=[a_mc,b_mc,c_mc,d_mc,e_mc];

//loop for my MovieClips
for (var i:uint=0; i<myClips.length; i++) {
	trace("loop is working");
	myClips[i].alpha=0;
	var myTween:Tween=new Tween(myClips[i],"alpha",Regular.easeOut,0,1,2,true);
}


This post has been edited by amitbiswas: 02 November 2009 - 01:44 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Randomly fade in and fade out animation issue!

#2 aedesign53  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-October 09

Re: Randomly fade in and fade out animation issue!

Posted 02 November 2009 - 08:35 PM

try setting the start,finish and duration values with the Math.random method

View Postamitbiswas, on 2 Nov, 2009 - 12:41 PM, said:

Hello friends,

I am new in AS3. Still learning. I have a bunch of MovieClips in my first keyframe. And I want to animate it randomly. I mean the movieclips should be fadein and fadeout randomly. the duration of Fade-in and Fadeout should be same for each MovieClips. Here I am stuck in a section. I have successfully completed Fade-in for each MC. But I do not understand what to do next! If anyone could give me some clue or help me, it will be great for me. here is the code I wrote.

Thanks
Amit

//Flash Makes that tween
import fl.transitions.Tween;
import fl.transitions.easing.*;

var myClips:Array=[a_mc,b_mc,c_mc,d_mc,e_mc];

//loop for my MovieClips
for (var i:uint=0; i<myClips.length; i++) {
	trace("loop is working");
	myClips[i].alpha=0;
	var myTween:Tween=new Tween(myClips[i],"alpha",Regular.easeOut,0,1,2,true);
}


Was This Post Helpful? 0
  • +
  • -

#3 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Randomly fade in and fade out animation issue!

Posted 03 November 2009 - 07:04 AM

Like aedesign53 said, you're going to be using the Math.random() function. In itself random generates a random value between 0 and 1, which isn't always useful. A more useful function is this one, which lets you specify boundaries for your random number:
function randNumber(min:int,max:int):int {
	  return Math.random() * (max - min) + min;
}



To create the delays in your animations you have two options:

One is to set up timers for each movieclip using the Timer class and a random number for the time. This will require quite a bit more code than you already have.

My preferred technique would be to use a class like Tweener. Tweener is a tweening class that has been around for a long time in various guises, and has a lot more options that Flash's native Tween class. Once imported, you could do your in tween like this:
Tweener.addTween(myClips[i], {alpha:1, time:2, delay:randNumber(.5,2), transition:"Regular.easeOut"});


This will Tween your clip from its current alpha value to 1 in 2 seconds after a random delay. You can even specify a function to be called when the tween is finished, which should get you nicely on the way to doing to out tween!
Was This Post Helpful? 1
  • +
  • -

#4 amitbiswas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-October 09

Re: Randomly fade in and fade out animation issue!

Posted 04 November 2009 - 05:40 AM

"thehat"
Thank you Sir. This is helpful. Can you please tell me where to put the 'tweener class' in my default flash folder? i mean how to install it? I have a little experience so I am asking this. Please don't mind.
Was This Post Helpful? 0
  • +
  • -

#5 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Randomly fade in and fade out animation issue!

Posted 04 November 2009 - 06:46 AM

If you look in the Tweener.as file, the first line starts with the word package. If I remember correctly it should be package com.caurina {. This shows you the path between the class and your fla, so if you have an fla in a folder called src, your Tweener.as file would go in the folder src/com/caurina/.
Was This Post Helpful? 0
  • +
  • -

#6 amitbiswas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-October 09

Re: Randomly fade in and fade out animation issue!

Posted 05 November 2009 - 07:25 AM

Here I am again. After 2 days, I came out with this. I am attaching the source fie. After I have used timer function for each MC and randomize the time interval, It wont work though. And it is playing repeatedly. Problem is Random function not working like what I want. Only whenever I am testing the movie, it randomize the time. But not for the interval between each MC.

Because I have a little knowledge of Package and using class with a separate AS file, I am working and coding in the fla file only.

Any kind of help please. Appreciated.

Here is the code.

import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
import fl.transitions.Tween;
import fl.transitions.easing.*;

/*a_mc.alpha = 0;
b_mc.alpha = 0;
c_mc.alpha = 0;
*/
var mc:Array=[a_mc,b_mc,c_mc, d_mc, e_mc, f_mc,g_mc];
var i:uint=0;
function delay(objEvt:TimerEvent)
{
	//var myTimer:Timer = new Timer(100, 2);
	//myTimer.start();
	trace("working!!!");
	var myTween:Tween=new Tween(mc[i],"alpha",Regular.easeOut,	0,1,2,true);
		i++;
}

function MyTimerFunc()
{
var myTimer:Timer = new Timer(Math.random() * 600, mc.length);
myTimer.addEventListener (TimerEvent.TIMER,delay);
myTimer.start();
//i++;
}

MyTimerFunc();

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#7 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Randomly fade in and fade out animation issue!

Posted 05 November 2009 - 08:31 AM

Your problem is that when you declare the Timer, you do so with a random number. That same number is then used for every iteration of the loop rather than a new random value each time. You could try resetting the delay property every time the loop completes, like this:
function delay(objEvt:TimerEvent)
{
	myTimer.delay = Math.random() * 600;
	//var myTimer:Timer = new Timer(100, 2);
	//myTimer.start();
	trace("working!!!");
	var myTween:Tween=new Tween(mc[i],"alpha",Regular.easeOut,	0,1,2,true);
		i++;
}


Was This Post Helpful? 1
  • +
  • -

#8 amitbiswas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-October 09

Re: Randomly fade in and fade out animation issue!

Posted 05 November 2009 - 12:43 PM

I am really grateful to you. Thank you Sir. It is working now. One more step and it will be done. I am now thinking of RANDOMIZE THE MOVIECLIPS! I mean it is always taking index[0] first and so on. I want to randomize the index number but I did not understand how to do that. As I am declaring "i" is a global variable. It increases "i++". But I want to randomize that. Sir, can you please help me once more time? Appreciated much.

Here is the Updated Code below.

import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
import fl.transitions.Tween;
import fl.transitions.easing.*;


var mc:Array=[a_mc,b_mc,c_mc,d_mc,e_mc,f_mc,g_mc];
var myTimer:Timer=new Timer(300,mc.length);
var i:uint=0;

for (var j:uint = 0; j<mc.length; j++) 
{
	mc[j].alpha=0;
}
function delay(objEvt:TimerEvent) 
{
	myTimer.delay=Math.random()*600;
	trace("working!!!");
	var myTween:Tween=new Tween(mc[i],"alpha",Regular.easeOut,0,1,2,true);
	i++;

}


function MyTimerFunc() 
{
	myTimer.addEventListener(TimerEvent.TIMER,delay);
	myTimer.start();
}

MyTimerFunc();



Was This Post Helpful? 0
  • +
  • -

#9 amitbiswas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-October 09

Re: Randomly fade in and fade out animation issue!

Posted 06 November 2009 - 05:23 AM

Hello again. I have just finished that random animation. After 3-4 hrs I have fixed the "array index randomize issue!". After that I have finished it. Many thanks to "thehat".

Any comments and critiques are welcome. here is the last edited code.

Regards
Amit

import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
import fl.transitions.Tween;
import fl.transitions.easing.*;


var mc:Array=[a_mc,b_mc,c_mc,d_mc,e_mc,f_mc,g_mc];
var myTimer:Timer=new Timer(0,mc.length);
var i:uint=0;
var index:Array=new Array();

for (var j:uint = 0; j<mc.length; j++) 
{
	mc[j].alpha=0;
}
function delay(objEvt:TimerEvent) 
{
	myTimer.delay=Math.round(Math.random() * (700-50)+50);
	//trace("working!!!");
	index[i]=indexUpdate(index);
	//trace("mc="+mc[index[i]].name);
	var alphaTween:Tween=new Tween(mc[index[i]],"alpha",Regular.easeOut,0,1,2,true);
	var XscaleTween:Tween=new Tween(mc[index[i]],"scaleX",Elastic.easeOut,0,1,2,true);
	var YscaleTween:Tween=new Tween(mc[index[i]],"scaleY",Elastic.easeOut,0,1,2,true);
	i++;

}

function indexUpdate(index:Array)
{
	var j:uint=Math.round(Math.random() * (mc.length-1-0)+0);
	if(index.indexOf(j)>=0)
	{
		//trace("same"+j);
		return indexUpdate(index);
		//trace("hello");
	}
	else
	{
		//trace("Not same"+j);
		return j;
	}
	//return indexUpdate(index);
}

function MyTimerFunc() 
{
	myTimer.addEventListener(TimerEvent.TIMER,delay);
	myTimer.start();
}

MyTimerFunc();


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1