Solved

Trigger Javascript at end of swf/flash movie

Posted on 2009-05-04
8
1,280 Views
Last Modified: 2013-11-11
I have a swf move in my HTML web page and in the page there is a javascript function call MovieEnd(). Is there a way that I can trigger this javascript function at the end of the movie from within the swf? How would I go about it? Thanks,
0
Comment
Question by:wilcor14
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 24295959
With the Flex-Ajax-Bridge you can call JavaScript functions in the page containing the SWF.
I guess this is no Flex-Feature so I guess this should work with all ActionScript3 solutions.

http://livedocs.adobe.com/flex/3/html/help.html?content=ajaxbridge_1.html
0
 
LVL 12

Expert Comment

by:alien109
ID: 24296040
0
 

Author Comment

by:wilcor14
ID: 24296432
Great, I think this is what we need.
Also just found out that in the flash file, we have an .FLV movie on the first frame. What we want to do is call the javascript at the end of the FLV movie but how do we know it is done? Thanks again.
0
Industry Leaders: 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!

 
LVL 22

Expert Comment

by:rascalpants
ID: 24296828
this all depends on how the FLV is being played...    can you look in the code and see what it being used to play the FLV...  normally something like this...

var theNS:NetStream = new NetStream( theNetConnection );
theNS.play( "streamToPlay" );



to detect if the FLV has ended, you can use a few different methods...  but you will need to setup an event listener and check for the NET_STATUS like the below...



rp / ZA





 
var theNC:NetConnection = new NetConnection();
 
//  put code here to check for NetConnection if you want
 
var theNS:NetStream = new NetStream( theNC );
theNS.addEventListener( NetStatusEvent.NET_STATUS, ns_EventHandler );
 
private function ns_EventHandler( evt:Event ):void
{
  var evtCode:String = evt.info.code;
 
  if( evtCode == "NetStream.Play.Complete" )
  {
    trace(" call ExternalInterface here ");
  }
 
}

Open in new window

0
 

Author Comment

by:wilcor14
ID: 24298367
rascalpants,
Thank you so much for your time. Just spoke with my developer and he gave me the code below this message. Based on what he gave me, how could we call a javascript funcation in the html page that the swf is embeded in? Would something like this work:
var url:URLRequest = new URLRequest(javascript:myfunction(););
navigateToURL(url);
 

import fl.video.VideoEvent;
flvp.addEventListener(VideoEvent.STOPPED_STATE_ENTERED, onVideoStopped);
function onVideoStopped(evt:VideoEvent):void
{
    var url:URLRequest = new URLRequest("http://google.com");
    navigateToURL(url, "_parent");
}

Open in new window

0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24298595

others have posted a link to some reference information above, but here is the code if you need it...


you first do a check to see if it is available... which means you are in a Browser, instead of the IDE...  then you need to pass the variable to the javascript function...


if you need the round trip example, you can see this question...  

http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/ActionScript/Q_24371711.html



rp / ZA


 
import fl.video.VideoEvent;
 
//  added rp
import flash.external.ExternalInterface;
var extIntAvailable:Boolean = ExternalInterface.available;
var theVariable:String = "rascalpants rocks!";
 
 
flvp.addEventListener(VideoEvent.STOPPED_STATE_ENTERED, onVideoStopped);
function onVideoStopped(evt:VideoEvent):void
{
    // added rp
    if( extIntAvailable )
    {
       ExternalInterface.call( "functionNameInJavaScript", theVariable );
    }
}

Open in new window

0
 
LVL 22

Accepted Solution

by:
rascalpants earned 500 total points
ID: 24435446


^ bump ^
 

please come back and finish up this question...


thanks,

rp / Zone Advisor
0
 

Author Closing Comment

by:wilcor14
ID: 31577579
My apologies for not getting back to you sooner. I was waiting on my developer to make sure it was all good and your code was perfect and works. Thanks so much. You saved me a ton in hours of research and money in not having to pay my developer to research it. Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

735 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