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

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");
}

Related

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

Load Flex4 application in Flash as3

I have created a plugin-enabled flash which reads a configuration file and loads several other flash files. All the files have been created by Adobe Flash CS5 . Recently i had to create a flex application which i want to load on stage of the main flash.
this.addChild(this.movieLoader);
this.movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadedM);
this.movieLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
this.movieLoader.load(new URLRequest(fmovie));
The LoadedM(..) is triggered every time and the loaded flash is placed into stage and positioned in LoadedM(..) .
When i load a FlashCS5 created swf, the loader.content is of type [object MainTimeline] while when i load the Flex4 application the loader.content is of type [object _Main_mx_managers_SystemManager]
My problem is that the flex application is not visible on stage nor the initialized/created events of the flex app are triggered even thow debug shows full load of the file.
I have already tried this solution but didnt do any good. i've checked the Event.INIT event of the loaded instead of Event.INIT and it's being triggered. But the anthropod debugged doest not report the the initialization of the flex app take place.
What am i missing?
Thanks in advance
You can read more about the problem at http://old.troygilbert.com/2009/05/loading-flex-based-swfs-in-as3-only-swfs/
If the above does not work, make sure that you are publishing your swf for flashplayer 10.2+

Force SWF (Flash file) to load LAST after rest of webpage

I have a rather complex flash clip that ends up bogging down the loading of the rest of my webpage.
Can I force the flash to wait to load until the rest of the site loads?
If you do not mind to have javascript you may use something like SFWObject 2 library, here is documentation page http://code.google.com/p/swfobject/wiki/documentation there is different methods for using it, so you just need pick up which is more appropriate in your case. Main idea you may trigger swf player initialization with javascript, so you could control time when this happen, and so using it just do that after onload event triggering. But assume problem cold be more complicated than just delaying your clip, so try to test it on different computers and browsers.

AS3 Loader's unloadAndStop odd behavior

I know the AS3 Loader's class unloadAndStop() supposes to unload and stop everything on a SWF's stage when I load one, but does it also changes objects within the library (even if they are not on stage?).
I'll describe my problem to clear it up: I am loading SWFs dynamically into my AS3 application and extract required symbols from them using applicationDomain and getDefinition. The stage of the SWF/FLA I am loading is empty, and all I have are exported symbols in my library.
The problem happens when I load symbols which have pre-compiled clips inside of them (in my case, a Partigen emitter, but I don't think it really matters), which probably has event listeners or timers - the code on these clips stops working and acts weird when unloadAndStop() is called by the Loader which loaded the clip's parent SWF. I assumed unloadAndStop() removes a required event listener from it, but not sure why (again, it's not on the stage).
I'd write my own kind of unloadAndStop() that filters these pre-compiled clips or checks what's truly going on there, but I am pretty sure that unloadAndStop() does things which are unavailable through the API.
What can explain this behavior? Anyone can think of a possible solution?
Thank you.
Make your loader in this way:
myLoader.contentLoaderInfo.addEventListener( Event.INIT , myLoaderHandler, false, 0, true);
It solves some problems due to unloadAndStop().

Can a Flash application alter the HTML of the page it's on?

Suppose I have a flash application; let's say a chess game. The user is playing against a computer opponent. After every move, I want the flash application to add the move's "description" into the HTML of the page.
Does flash have this ability?
Are there any common round-about ways of doing this? Maybe the flash app updates a database, and some AJAX on the page frequently checks the database and adds content when appropriate.
Are there any examples on the web of this type of functionality?
From ActionScript, you can use ExternalInterface to call Javascript functions in the client browser, so yes, this is possible.
I see in my ActionScript 3.0 Bible, chapter 36 "Interfacing with JavaScript" that you can use flash.external.ExternalInterface to "both call JavaScript functions from Flash and to call ActionScript functions from JavaScript".
Therefore, you can change any DOM element from a JavaScript that you activate from Flash.
Your ActionScript code can access javascript methods that update the page's DOM.
You can access Javascript methods using the ExternalInterface class. more details at:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html