I am trying to call call action script function from JS but i get the following error
Error: getFlashMovie(swfobjectID).sayWhat is not a function
Can any body let me know what am i doing wrong here
<html>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="myMovieName" WIDTH="225" HEIGHT="200">
<PARAM NAME="movie" VALUE="ax.swf" /> <PARAM NAME="quality" VALUE="high" /> <PARAM NAME="bgcolor" VALUE="#FFFFFF" /> <EMBED href="ax.swf" src="ax.swf" quality=high bgcolor=#FFFFFF NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash"> </EMBED> </OBJECT>
<script>
function getFlashMovie(movieName) {
alert("In get Flash Movie");
document.getElementById(movieName).setAttribute("name", movieName);
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
function sayWhat()
{
alert("In call as");
var swfobjectID = 'myMovieName';
alert(swfobjectID);
//call flex function
getFlashMovie(swfobjectID).sayWhat();
}
</script>
<input type="button" onclick="javascript:sayWhat();" value="Click Me" />
</html>
MXML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initCamera()">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import mx.controls.Alert;
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;
import flash.external.*;
import flash.external.ExternalInterface;
public function sayWhat():void {
Alert.show("Hi");
}
public function initCamera():void {
//stop();
ExternalInterface.addCallback("sayWhat", sayWhat);
}
]]>
</mx:Script>
</mx:Application>
You might need an other kind of workaround in js to call the flash function from any browser.
Here i share my way to accomplish this (hope it is not deprecated yet...). You need a javascript class (i named it FO):
You will need an initialization method (or extend the existing one):
and for calling the desired method:
When calling from javascript try:
Here is a working sample application that calls your flex sayWhat funciton from javascript.
It contains 4 files:
ax.mxml
,call_flfunc.html
,ax.js
andax.css
.You should put the last three files and the generated ax.swf file in the same folder on your web server (or modify their path where they are referenced), and it will work.
ax.mxml: your main flex application's structure
call_flfunc.html: the html content into which the ax.swf is embedded
ax.js: contains all the necessary javascript classes and functions
ax.css: the style sheet applied to the
call_flfunc.html
pageI hope it's understandable, and you can work from it.