Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

actionscript 3 - How to notify the HTML container that the SWF has finished, using swfobject

I am embedding a flash object (swf file) into an HTML page. The object is written in as3 and built using Flash Builder. Its purpose is to show some animation, then finish.

It is really important to me to be able to notify the container that the animation has finished, but I can't find anything that works. I am using swfobject version 2.2.

Tried both on Chrome 40 and IE 11.

HTML (sample):

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <script type="text/javascript" src="js/swfobject.js"></script>
    <script type="text/javascript">
        function flashFinished() {alert('finished!');}
    </script>
    <script type="text/javascript">
        var flashVars = {}
        var flashParams = {allowscriptaccess : 'sameDomain'}
        var flashAttributes = {id : 'myflash', name : 'myflash'}
        swfobject.embedSWF('myflash.swf', 'flashObject', '960', '720', '9.0.0', 'swf/expressInstall.swf',
                flashVars, flashParams, flashAttributes);
    </script>
</head>
<body>
    <div id="flashObject">
        <p>To view this page please make sure that an updated version of Adobe Flash Player is installed.</p>
    </div>
</body>

AS3 (sample):

package
{
    public class myflash extends Sprite
    {
        public function myflash()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            startPlay();
        }
        private function startPlay() : void {
            // do whatever, then make sure function finishPlay is called in the end
        }
        private function finishPlay(event:TimerEvent) : void {
            if (ExternalInterface.available)
                ExternalInterface.call('flashFinished');
        }
    }
}

My "flashFinished" function gets never called. Can anyone suggest what am I doing wrong? Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In case the job of flash code is done and you don't need it anymore, just terminate the javascript in as3:

var exitStr:String = "javascript:terminate()";
navigateToURL(new URLRequest(exitStr),"_self");

And then add a onUnload function in HTML which will be called at that point:

onUnload="flashFinished();"

note: I used this code with swfobject v1.4 not sure about v2.2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...