Skip to main content
hartz
Inspiring
July 9, 2019
Answered

Code to reset entire Stage

  • July 9, 2019
  • 2 replies
  • 1174 views

I am a novice user.  I have a project in Animate where I have two external swfs that load.  Everything loads and unloads fine when you first click a button to load it, then unload it.  The problem is that once I load and unload, the other swf will not load.  Whichever one I click first will load and unload.  I don't know why this is happening.  I use a projector file (publish export) and this is where it doesn't work.  Everything works fine when I simply do a test scene.

So here is my question.  When I go back to the page where the buttons are, is there a code that I can put on frame one so that when the playhead reaches that frame it resets everything?  In my mind this is the solution to circumventing this issue.

I have tried to do multiple searches for such code and cannot find anything.

Paul

This topic has been closed for replies.
Correct answer kglad

My original question still seems to be where I'm at.  I had thought that the size of my Photos SWF was just too big so I had broken it into two swfs.  I have since moved it back to one swf since I was getting the same result.  The code works when published to .swf, so I know it has nothing to do with code per se.  The problem is when I publish to Win Projector to make it executable on a local machine...something I have been doing for about 13 years.  When the .exe is deployed, it gives me one launching of my swf.  On subsequent attempts it goes to the launch frame but then doesn't load.  The return to main still works, but all attempts after the first successful launch fail.  If I ESC then relaunch the .exe I can get that initial loading.  I can live with this for now, but I do these all the time and I would really like to resolve this.

In my publish settings I have tried changing the TARGET to Flash Player 30 (as well as changing it to other versions)  I have even forced updated my Flash Player even though Windows 10 claims it has it built in.  There are a few other options in the publish settings which don't work for me.

I'm led to believe the problem is within the publish step because the swf works.  I prefer the Projector mode because I want it to go full screen and the 100s of prosecutors I work with want to be able to simply launch and go.

If there was only a way for even a button to reset the .exe without closing and relaunching I could live with that.  I cannot figure out why all of a sudden this fails when previously it always worked.


try using one loader:

// first frame of first scene:

var myLoader:Loader;

if(!myLoader){

myLoader = new Loader();

var urlA:URLRequest = new URLRequest("JonesPhotosA.swf");

var urlB:URLRequest = new URLRequest("JonesPhotosB.swf");

addChild(myLoader);

}

//scene where you want to load urlA

myLoader.load(urlA);  // corrected from myloader typo

// unload button

btnMainP.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_12);

function fl_ClickToGoToAndStopAtFrame_12(event:MouseEvent):void

{

myLoader.unloadAndStop();

gotoAndStop(1,"Main");

}

///// scene where you want to load urlB

myLoader.load(urlB);

// unload button

btnPhoto2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_14);

// same as your other function so it's redundant

function fl_ClickToGoToAndStopAtFrame_14(event:MouseEvent):void

{

myLoader.unloadAndStop();

gotoAndStop(1,"Main");

}

2 replies

Legend
July 9, 2019

There is no magic reset button. Anything that gets touched in the global state will have to be manually reset.

If you're loading directly into the root stage... don't. Load into an empty container clip that's on the stage. Even better, dynamically instantiate the container clip when you load the SWF, then destroy it when you unload it. That will get rid of any container-level contamination that the loaded SWFs are leaving behind.

And for the love of god, don't use scenes.

hartz
hartzAuthor
Inspiring
July 9, 2019

I have to use scenes because I came from AS2 and am not a programmer. It’s the way my brain works. I create trial exhibits and my programming is crude but I get it done, usually.

I don’t know what it means to load into an empty container clip. Can you point me to a tutorial or modify my code?

Paul

kglad
Community Expert
Community Expert
July 9, 2019

what code do you use to load and unload?

hartz
hartzAuthor
Inspiring
July 9, 2019

var myLoaderA:Loader = new Loader();

var urlA:URLRequest = new URLRequest("JonesPhotosA.swf");

myLoaderA.load(urlA);

addChild(myLoaderA);

btnMainP.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_12);

function fl_ClickToGoToAndStopAtFrame_12(event:MouseEvent):void

{

myLoaderA.load(urlA);

removeChild(myLoaderA);

SoundMixer.stopAll();

gotoAndStop(1,"Main");

}

/////Then my other one, on a separate scene is:

var myLoaderB:Loader = new Loader();

var urlB:URLRequest = new URLRequest("JonesPhotosB.swf");

myLoaderB.load(urlB);

addChild(myLoaderB);

btnPhoto2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_14);

function fl_ClickToGoToAndStopAtFrame_14(event:MouseEvent):void

{

myLoaderB.load(urlB);

removeChild(myLoaderB);

gotoAndStop(1,"Main");

}

My main page is my landing page. When it goes back to “Main” the button to get to the scene works, but the swf won’t load.

kglad
Community Expert
Community Expert
July 9, 2019

i assume you want to load those swfs when you go the frames that contain the code above the button codes, and the button's are supposed to unload the loaded swfs.  if that's true, use:

var myLoaderA:Loader;

if(!myLoaderA){

myLoaderA = new Loader();

var urlA:URLRequest = new URLRequest("JonesPhotosA.swf");

addChild(myLoaderA);

}

myloaderA.load(urlA);

btnMainP.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_12);

function fl_ClickToGoToAndStopAtFrame_12(event:MouseEvent):void

{

myLoaderA.unloadAndStop();

gotoAndStop(1,"Main");

}

/////Then my other one, on a separate scene is:

var myLoaderB:Loader

if(!myLoaderB){

myLoaderB = new Loader();

var urlB:URLRequest = new URLRequest("JonesPhotosB.swf");

addChild(myLoaderB);

}

myLoaderB.load(urlB);

btnPhoto2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_14);

function fl_ClickToGoToAndStopAtFrame_14(event:MouseEvent):void

{

myLoaderB.unloadAndStop();

gotoAndStop(1,"Main");

}