0

I need to get some information of a swf "e-learning" movie. I need to know in wich part of it the user has stoped watching and or if user has watched until it's end. I am not developing a LMS, so I need just simple features. Are there any way to retrieve this information from within flash with javascript? If so, do you know where can I find some documentation about it?

Thanks in advance.

1 Answer 1

1

You can use the Adobe Flash's ExternalInterface API to communicate between Javascript and ActionScript. Browser Support: IE 5.0+, Firefox 1.0+, Safari 1.3+, Opera, Chrome (versions N/A but old enough).

Flash TO Javascript Communication;

In your AS3/Flash:

function sendToJS(obj:Object):void {
    if (ExternalInterface.available) {
        ExternalInterface.call("onFlashCall", obj);
    }
}

In your HTML/Javascript:

<head>
    <script type="text/javascript">
        function onFlashCall(obj) {
            console.log("Data received from Flash: ", obj);
        }
    </script>
</head>

Javascript TO Flash Communication;

In your AS3/Flash:

public function onJavascriptCall(obj:Object):String 
{ 
    console.log("Data received from Javascript: ", obj);
} 
ExternalInterface.addCallback("sendToFlash", onJavascriptCall);

In your HTML/Javascript:

<head>
    <script type="text/javascript">
        function sendToFlash(obj) {
            var flashElem = document.getElementById("flashObject");
            flashElem.sendToFlash(obj);
        }
    </script>
</head>

<body>
<!-- Embeded Flash SWF -->
<object id="flashObject"...> 
    ... 
    <embed name="flashObject".../> 
</object>
</body>

Important: In Flash, not to get a security error:
In the object tag for the SWF file in the containing HTML page, set the following parameter:

<param name="allowScriptAccess" value="always" />

In the SWF file, add the following ActionScript:

flash.system.Security.allowDomain(sourceDomain);

So, in your case:

Call sendToJS() method inside your player's corresponding event handlers:

protected function onStopClick(event:MouseEvent):void
{
    sendToJS("User has clicked the STOP button.");
}

protected function onPlaybackFinish(event:Event):void
{
    sendToJS("Playback is complete.");
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Onur YILDIRIM, I'll try this approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.