?
Solved

How to restart/reset Flash movie from scratch?

Posted on 2009-12-18
7
Medium Priority
?
7,606 Views
Last Modified: 2013-11-11
Hi Experts,

I have a flash movie which uses particle components and loads external movieclips.  I'd like to add a 'restart' button to play the movie fresh from the beginning, I have a button set up, but it only sets the movie back to Frame 1 - this works for most of the animation, but the particle component and the external movie clips seem to remain on, and the movie plays much slower the second (and subsequent) times.

I need a method to perform a 'true' restart of the whole movie (similar to when you refresh the web browser page, but all perfromed internally inside the Flash movie).

I'm using Flash CS4 and AS3.

I'll be very grateful if someone can recommend a solution for this! :-D

Cheers,

Luke
0
Comment
Question by:Lukasx123
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:TanLiHao
ID: 26078911
Please post the particle generating code and the code used to add the movie clips onto the stage.

Otherwise, posting the source will help.

Alternatively, you might want to try the following.

Add the code into the function that you call when the button is clicked,

For example you reset button is named reset then you do this

reset.addEventListener(MouseEvent.CLICK, resetSWF);

function resetSWF(e:MouseEvent);void {

for (var i:int = 0; i < stage.numChildren; i++) {
    removeChildAt(i);
}

gotoAndStop(1);
}
0
 

Author Comment

by:Lukasx123
ID: 26079161
Hi,

Thanks for your reply!

The code I'm using to load the external swfs is below:

I haven't added a lot of code to the particle component, it's pretty self-contained.  I bought it from a website, there is a bit of information about how it works here:  http://www.flashextension.net/HelpPanel/Help/Particulator%20component/001_about.html

Thanks,

Luke
var request:URLRequest = new URLRequest("TrailingNumbersPreloaderFINAL.swf");
var loader:Loader = new Loader()
loader.load(request);
addChild(loader);

Open in new window

0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 26079200
Hmm, I need your source file for TrailingNumbersPreloaderFINAL.swf as this will not help me.

Have you tried the above code?

Is the the trailing numbers preloader the swf that generates the particles? Is the reset button in that swf or not? If it is not, it would not work.
0
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!

 

Author Comment

by:Lukasx123
ID: 26079286
I did try your code, but I got the following error messages:

1084: Syntax error: expecting identifier before for.
1084: Syntax error: expecting colon before i.
1084: Syntax error: expecting rightbrace before rightparen.

They all refer to the following line of code:

The particles are in the 'parent' swf file.  The two external movies that are called control some trailing numbers (also a particle effect) and a snow effect.

There is quite a lot of code in various places within the movie, and in the external movies to list here.

Here is a link to the actual movie as it stands right now, so you can see what I'm talking about:

http://www.era.co.uk/xmas2009/xmas_ecard.htm

Cheers,

Luke

for (var i:int = 0; i < stage.numChildren; i++) {

Open in new window

0
 
LVL 14

Accepted Solution

by:
TanLiHao earned 1000 total points
ID: 26086134
You probably didn't put in the code correctly.

Anyway I really need the source file to write code for resetting the .swf.


Otherwise, you can use swfobject to remove the swf and embed the swf again when the reset button is clicked. You can use ExternalInterface or navigateToURL to call the javascript to reload the swf.

However, you are not using SWFObject to embed the swf although you have included it.

Alternatively, you can create a loader with the same dimensions as this swf and once the movie is loaded, add an event listener to the reset button to reload the movie. Therefore you need to remove the event listener in the original swf otherwise your page will reload as well.

Or you can add a reset button yourself in the loader and swap the index of the loader and button after the loader is loaded complete.

Anyway look at the code snippet for example. I commented the new button code away as I think the adding an event listener to your button_replay is better. However, if you choose to use the new button code, remove loader.content.button_replay.addEventListener(MouseEvent.CLICK, reloadSWF); and uncomment the code.

var request:URLRequest = new URLRequest("xmas_ecard_final.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, addReset);
loader.load(request);

addChild(loader);

//resetbtn.addEventListener(MouseEvent.CLICK, reloadSWF);

function reloadSWF(e:MouseEvent) {
	loader.load(request);
}

function addReset(e:Event):void {
	//swapChildren(loader, resetbtn);	loader.content.button_replay.addEventListener(MouseEvent.CLICK, reloadSWF);
}

Open in new window

0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 26086139
Oops, there is some problem with experts exchange next line formatting in the code.

function addReset(e:Event):void {
        //swapChildren(loader, resetbtn);       loader.content.button_replay.addEventListener(MouseEvent.CLICK, reloadSWF);
}

should be acctually

function addReset(e:Event):void {
        //swapChildren(loader, resetbtn);
        loader.content.button_replay.addEventListener(MouseEvent.CLICK, reloadSWF);
}
0
 

Author Closing Comment

by:Lukasx123
ID: 31667683
Thanks for your help!

Luke
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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
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 goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 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