[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

stop duplicating a movieclip

Posted on 2009-05-01
4
Medium Priority
?
171 Views
Last Modified: 2013-11-11
i want to know how to stop this after 15 seconds.

or delete it after 15 seconds


star_mc._visible = true;
var i:Number = 0;
var total:Number = 90;
for( ; i < total; i++ )
{
	star_mc.duplicateMovieClip("star"+i, i);
	this["star"+i]._x = Math.floor(Math.random() * 800);
	this["star"+i]._y = Math.floor(Math.random() * 600);
	this["star"+i].gotoAndPlay( Math.floor(Math.random() * star_mc._totalframes) );
	
}

Open in new window

0
Comment
Question by:TecServ
  • 3
4 Comments
 
LVL 6

Expert Comment

by:gxp071
ID: 24282716
the quickest way is with an interval and a flag,  or you can put the loop into a function and clearing using an interval  The code below shows an interval with a boolean flag.
star_mc._visible = true;
var i:Number = 0;
var total:Number = 90;
var breakFlag:Boolean = false;
 
for( ; i < total; i++ )
{
        if(breakFlag){ break; }
 
        star_mc.duplicateMovieClip("star"+i, i);
        this["star"+i]._x = Math.floor(Math.random() * 800);
        this["star"+i]._y = Math.floor(Math.random() * 600);
        this["star"+i].gotoAndPlay( Math.floor(Math.random() * star_mc._totalframes) );
        
}
 
function stopLoop (){
 breakFlag = true;
 clearInerval(timerLoop)
}
 
var timerLoop = setInterval(stopLoop,15000);

Open in new window

0
 
LVL 6

Expert Comment

by:gxp071
ID: 24282728
sorry you will need to put the function and interval above the for loop.
0
 

Author Comment

by:TecServ
ID: 24283206
where exactly do i put it, i tried almost everywhere and it doesn't seem to make a difference.
0
 
LVL 6

Accepted Solution

by:
gxp071 earned 500 total points
ID: 24283339
hay have shown below,  and have tested it aswell,  added two traces so as can see whats happending in the output window but not required.

also had a typo on the clearInterval();

anyway should work now let me know if you have anymore problems.
star_mc._visible = true;
var i:Number = 0;
var total:Number = 90;
var breakFlag:Boolean = false;
 
function stopLoop(){
	breakFlag = true;
	trace('Stopped');
	clearInterval(timerLoop);
}
 
var timerLoop = setInterval(stopLoop,15000);
 
for( ; i < total; i++ )
{
        if(breakFlag){ break; }
 	trace(breakFlag + ' ' + i);
        star_mc.duplicateMovieClip("star"+i, i);
        this["star"+i]._x = Math.floor(Math.random() * 800);
        this["star"+i]._y = Math.floor(Math.random() * 600);
        this["star"+i].gotoAndPlay( Math.floor(Math.random() * star_mc._totalframes) );
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
Suggested Courses
Course of the Month19 days, 10 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question