ExternalInterface.call crashes flash for Chrome - actionscript-3

There is a swf file on my website, when i click a button on it. It calls a js function, this function removes this swf and puts another.The problem is it crashes on Chrome.
I am confused about the problem. These are the cases:
-If i comment out the code which removes swf file and add next swf file, no crash happens.
-If i call javascript function(which is called from swf) from my side, it works fine.

Just an idea:
Make a test to let the call from the swf return before removing the swf from the DOM. Try something like setTimeout to let the call from the swf return and then let the remove-code be triggered by the timeout.
What kind of crash is it? AS3 exception or chrome crash?

Related

Actionscript ExternalInterface syntax error

I have created a simple container app whose purpose is to:
play an embedded flv by clicking a button onscreen
activate an external interface call (this records the fact that the person has watched the video)
That's it.
I have it working partially. I have a button on scene 1 with the "click and go to next scene" code snippet attached to it. I click it and it happily moves on to scene 2 where the flv video plays beautifully. The problem happens when I try to insert the code that the external developer told me to use to make the connection between my flash file and IT's back end work.
Here is the recommended code:
ExternalInterface.call("recordScore()”);
Unfortunately, as soon as I enter this code, there is a syntax error and the movie no longer plays. I added the code on a frame at the end of the movie.
I am no sure that the syntax the developer sent was correct, nor do I know where to insert this code into the proper place.
It looks like there is a closed double quotes (”) in what you pasted:
ExternalInterface.call("recordScore()”);
Assure quotation marks, and you do not need the () on the JavaScript function you're calling:
ExternalInterface.call("recordScore");
When running from Flash Projector (as in Ctrl+Enter), you can test whether External Interface is available; otherwise, an exception is thrown at runtime:
if (ExternalInterface.available) {
ExternalInterface.call("recordScore");
}
Fortunately, I found some code in the former employee's files that seems to have worked:
ExternalInterface.call
(
"recordScore()"
);
Hopefully this will connect with the database and resolve the issue so I can go back to making videos.
Thank you so much for your help!
Regards!

How to tell when ExternalInterface is available when hiding and showing a swf

I've got a swf with some js callbacks registered using ExternalInterface. I hide and show the swf repeatedly, and I've learned that ExternalInterface is not available when the swf is hidden. I also noticed that the swfs constructor is called every time it shows again, which I've used to make sure I don't try to call an ExternalInterface function before its available. This makes me wonder though if there is also some way to reliably tell from inside the swf when it is hidden? I know as3 classes don't have destructors, but is there anything similar that could be used to fire an ExternalInterface event right before the swf becomes unavailable again? REMOVED_FROM_STAGE doesn't seem to help out with detecting this as it doesn't fire at all.
I'm using several methods of hiding and showing btw. Sometimes using angular's ng-hide/ng-show and sometimes the swf is within a bootstrap modal window.
Also, I've noticed Flash Builder can somehow tell when the swf unloads. I can add a button that sets 'display: none' on the embedded <object> and I get the [Unload SWF] message in the console in Flash Builder. Is this just a feature of the debug player, or is there some secret event Flash Builder knows of that I have yet to find?
You can use this code to check if a SWF can call ExternalInterface:
if(ExternalInterface.available) {
ExternalInterface.call("console.log","hello browser");
}

Preloader does not work online

I've made a project that uses a preloader in the scene 1 and the content continues in the scene 2. The preloader have the follow code:
stop();
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
this.loaderInfo.addEventListener(Event.COMPLETE, loaded);
function loading(e:ProgressEvent):void {
text_txt.text = "Loading... "+int((this.stage.loaderInfo.bytesLoaded/this.stage.loaderInfo.bytesTotal)*100)+"%";
}
function loaded(e:Event):void {
play();
}
When i tested in the local machine it worked, but when i upload to the server online the preloader shots to 100% and don't show the progress percent.
I've tried export classes to the frame 2 and error still continues. I'm using just only one TextField on the stage.
It's most likely one of the following two issues:
The .swf is delivered by the server gzipped. This prevents the swf from starting until the whole file has been downloaded. You can see if it's being gzipped by opening the Dev tools (F12) in Chrome, go to the "network" tab and select the .swf and check for "Content-Encoding:gzip" under the "Response headers" headline. Note that you need to clear the browser cache first to make the browser download the .swf from the server, otherwise the Response headers won't be visible. Here's a relevant thread talking about gzip and swf: Preloader flash AS3 it's no longer working [GZIP issue].
You embed the .swf on the html page with wmode parameter set to "transparent". It's a known bug several years old, so I would be surprised if that is still relevant today. But if you do embed with wmode it's a quick test to remove that parameter and see if the problem is resolved.

eventListener flash

I am working with AS3.
I simply can't remember what eventListener to use if I want it to start my function up by it self (as in not a mouseevent.CLICK)
It is intended for a quick flash banner, that should just start up when ever a user enters the site where it is located.
You don't need to hook into an event for this.
When the site is loaded, the swf will load and play.
If the site is refreshed, then the swf will be reloaded (from cache) and be replayed
So any code that instanciates your app will be executed.
You can do loaderInfo.addEventListener(Event.COMPLETE, _YourFunctionToBeExecuted) if you want to do something when your swf file has been loaded completely
Or
You can do addEventListener(Event.ADDED_TO_STAGE, _YourFunctionToBeExecuted) if you want to run your code when the display object has been added to the stage

Loading SWF in AS3 but flash keeps repeating constructor function, what should I do?

I am importing several external files using the Loader-class, and one of them is an swf-file. When doing so (I had done it successfully before, so did not expect any issues), I ran into all sorts of errors, and finally Flash crashed.
I put down a trace in the constructor function, and it didn't trace just once, but kept on tracing, suggesting that the constructor was stuck on loop. I guess the loading of too many of the same swf is what causes flash to eventually crash.
Here is my code (the swf im loading is now a simple test-file which contains an image and no code):
private var slides:Loader = new Loader();
public function DocumentClass()
{
trace(1)
slides.load(new URLRequest("Resources/Slides.swf"));
slides.contentLoaderInfo.addEventListener(Event.COMPLETE, SlidesComplete);
}
public function SlidesComplete(evt:Event):void
{
slides.contentLoaderInfo.removeEventListener(Event.COMPLETE, SlidesComplete);
addChild(slides);
}
This traces "11111111111..." and everything dies in the end.
HELP!
Try putting a stop() action at the top of the swf you load in (either in actionscript, or on the timeline). It's possible that the swf is being loaded in and is running a play and running on loop in the mean time (hence your code running over and over).
I would do a progress watch until the swf is fully loaded, then jump to your display frame:
Create a section for loading (your choice if you want to use a preloader)
Create another section (set of keyframes) for loaded content. I use keyframes because it's easy, but you could also wait to instantiate classes until loading is complete.
Below is a snippet I occasional build from:
// stop the playhead from moving ahead
stop(); // you can also use gotoAndStop("loading"); if you want
function loaderProgressHandler(event:Event):void {
// switch the framehead to main which will show your content
if(event.bytesLoaded >= event.bytesTotal) {
event.target.removeEventListener(Event.PROGRESS, this.loaderProgressHandler);
this.gotoAndStop("main");
}
}
this.loaderInfo.addEventListener(Event.PROGRESS, this.loaderProgressHandler);
Hope that helps!
I was just stuck on this same problem.
In my case it turned out that the problem was down to the swf having the same document class name as the swf that was loading it.
eg. Main.as was loading another swf that also had its document class called Main.as - Changing this to anything else solved the infinite loop.