How can I use javascript to determine when a Flash movie has ended? ie like an SWF "MovieEnded" event
The right way would be to modify the flash movie to call a javascript function whenever it has ended. The right way to call the javascript function would be using the ExternalInterface class:
ExternalInterface.call("javascriptFunction");
However, if you don't have access to the inner workings of the flash movie, the simplest way would probably be to just poll the current frame number of the flash movie on some interval and determine whether or not it has ended. An ugly and deprecated way to get the current frame number of the flash movie would be to use the ancient, but working, TellTarget method:
document.getElementById('idOfEmbeddedFlash').TCurrentFrame('/');
I would recommend that you add some code into the final frame of the SWF which would trigger the Javascript code in your HTML page. You can use getURL to do this simply, or there are some more robust methods.
Related
It is possible to block a link from flash object? (Link is hardcoded inside a flash object).
no, the link is managed by flash plugin.
At most you can just overlap the flash object with an element (with a transparent background) so the link is not clickable (but this is not a real solution since it can be circumvented)
You cannot do that, since Flash "lives in it's own world" in the browser. All JavaScript sees is an object, it doesn't know what's in there.
If possible, generate a new swf which embeds the current flash swf & disable its mouse events, using:
mc.mouseEnabled = false;
You can control the new swf by defining an ExternalInterface & calling from javascript, using:
document.getElementById('flash-obj').ExternalMethodInFlash();
Is there a way (in javascript) to detect if an embedded .swf was created with Flash Professional or Flex.
We have a page with several tabs, each of which can contain an .swf. All tabs are defined within the same HTML file and the javascript framework calls a .rewind() and .play() on the swf when the containing tab becomes active.
This works great on regular flash animation, making sure they start playing from the beginning when the tab is opened. On an swf created with Flex however, the rewind and play wreak havoc on the Flex framework and the application doesn't load.
The best way we've come up with to detect Flex is to count the number of frames the .swf has. With flex that's always 2. But this doesn't sound like the best way.
We've also tried to add a callback method with ExternalInterface on the Flex application preinitialize event. Unfortunately this event is called quite late in the application startup and the javasctipt code checks the callback before the Flex code has added it.
Is there any other way to detect (from javascript) if the .swf was created using Flex?
Short answer, no. Flex IS Flash; it's just an added layer on top of Flash to increase productivity in development.
However, there might be a solution for you, but I need to know if you created the swfs yourself and if you can modify them. If you can, I would use an ExternalInterface callback to 'play' your swf by calling that function in JS (ie. document.getDocumentById('swfId').someFunction();).
The other solution would be to have all your swfs play immediately after load and then only load them in JS when needed (and not doing preloading). If you need to 'rewind', just reload them again (should be easy enough if you're using SWFObject, just remove and add back).
Ok, so, to answer my own question, DownloadProgressBar (loaded in the first frame) can be customized (overloaded).
So, this is the custom progress bar, that adds an isFlex() callback method to Javascript:
package flexidentifier {
import flash.external.ExternalInterface;
import mx.preloaders.DownloadProgressBar;
public class FlexIdentifierDownloadProgressBar extends DownloadProgressBar {
public function FlexIdentifierDownloadProgressBar() {
super();
ExternalInterface.addCallback("isFlex", callback);
}
protected function callback():String {
return "true";
}
}
}
Don't forget to add it to the Application:
<s:Application xmlns:s="library://ns.adobe.com/flex/spark" preloader="flexidentifier.FlexIdentifierDownloadProgressBar">
</s:Application>
It would have been nice if the people at Adobe put it in the Flex framework to start with.
is it possible to change the playback speed of a flash object without having to recompile the flash object, i.e through the html attributes or javascript?
thanks in advance
No, but you can call a function within your SWF file from JavaScript (ExternalInterface. addCallback) that changes your animation's FPS... However, you would need to create the function in your flash file and recompile it once.
You could also create a loader SWF that has this functionality, and load your old flash movie from it.
I need to create a splash page type thing. It needs to play a flash movie and then when that movie has finished show a full screen image using html/js. THe movie will be flash and the image display will be javascript powered.
I have no idea how to do this on one page. Any help would be amazing.
Thank you for reading.
You'll want to use ExternalInterface. Example:
try {
ExternalInterface.call("myfunction");
} catch(e:Error) {
trace(e)
}
Depending on how your flash movie is constructed, when the animation reaches the last frame, running ExternalInterface.call("myfunction"); will call a function in javascript called "myfunction". Example:
<script type="text/javascript">
function myfunction()
{
alert("hello!"); // replace with some jquery
}
</script>
I can't really say how to put it into your movie, because I don't know if your movie is constructed using actionscript animation, or timeline animation, or you're wanting to play a flash video. (If you are using a video, you can attach an event listener for Event.COMPLETE and do your c all there). If its an actionscript animation, you'll need to find the end of a tween or something.
Wrapping it in a try/catch is just to be safe. You'll need to make sure when you embed the swf, you have allowScriptAccess=always or sameDomain. Reference here
There may be a better way to do this, but inside the flash movie you can use ExternalInterface to call javascript functions. So, you can set up an actionscript function to run when the movie ends, and have it a call a javascript function to do whatever you need to do with the web site.
-- Disclaimer --
I don't have the cash to upgrade my Flash, so I'm still using actionscript 2. The object I mentioned may be deprecated now - but it will still work.
Is there any way of detecting an error when a Flash-plugin loads its content?
Basically, what I want to do is to provide some alternate content, in case something goes wrong when the Flash-plugin tries to load it's .swf file.
The .swf file is managed by a CMS type system and hence I want to create some kind of fall back default content, in case something has gone wrong, e.g the .swf file has been deleted.
I know how to detect the flash version etc. but I can't find any resources on this type of scenario.
If you are embedding with SWFObject, then I think you want to look at the result of your embedding javascript:
var so = swfobject.createSWF( ... );
Here are some details:
http://pipwerks.com/lab/swfobject/test-embed-success/index.html
Unfortunately there is no such event and you can't detect this with SWFObject either.
It is only possible if you own the SWF files.
NOTE: success is report as true if the minimum Flash player required is available and that the Flash plugin-in DOM element for the SWF was created. SWFObject cannot detect if the swf file request has actually loaded or not.
from: https://code.google.com/p/swfobject/wiki/api