Call Actionscript function from Javascript

Can anyone show me a simple example of calling an
actionscript function from within javascript? Everything I have
found searching online refers to using the ExternalInterface but I
was sure I also read that Adobe Air does not support it. I am
currently using htmlloader to load a html page containing
javascript into an <mx:HTML>. But I cant seem to touch the
actionscript functions from within javascript. I am specifically
trying to work with the FCKeditor that I have integrated so if
anyone has any examples other methods of integrating the editor I
would love to see them as well.
Thanks!

Let's assume u have embeded swf object named "flashObj"
<embed src="MYSWF.swf" quality="high"
width="100%" height="100%" name="flashObj"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="
http://www.adobe.com/go/getflashplayer">
</embed>
On each time onblur is called it invoke AS function
myActionScriptFn
window.onblur = function() {
if(flashObj != null){
flashObj.myActionScriptFn(navigator.appName);
You need to add a listener in Action Script code
ExternalInterface.addCallback("myActionScriptFn",
myActionScriptFn);
public function myActionScriptFn(appName:String):void
// Any code here
Regards

Similar Messages

  • Help with calling java functions from javascript

    I am using javax.script to interpret javascript from a java applet. it loads the js file into a string, and then does engine.eval(script_string). My question is, how would I make functions in the class file that are available to javascript?
    Update: Instead of that, I am loading a js script that will contain all of the usable functions. Here it is:
    //core.js for Javasphere 0.31
    var pkgs = new JavaImporter(java.lang, java.lang.System, java.awt);
    with(pkgs) {
    function Abort(msg) {
            var graph = new Graphics();
            g = graph.getgraphics();
            g.drawString(msg, 20, 20);
    }When I do engine.eval("Abort(\"something\")"); it throws this error:
    javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: error instantiating (0): class java.awt.Graphics is interface or abstract (<Unknown source>#8) in <Unknown source> at line number 8

    Eggbertx, let's start from scratch if you don't mind. Say you have this Applet
    pubic class MyApplet extends Applet
      String message;
      //CALL THIS METHOD FROM JAVASCRIPT
      public void setMessage(String msg)
        message = msg;
        // this saves you from having
        // to call getGraphics() from JavaScript
        repaint();
      public void paint(Graphics g)
        g.drawString(message, 10, 30);
    }Then in your HTML file you may have something like this:
    <input type="text" id="msg" value=""></input>
    <input type="button" value="Set Message" onclick="setAppletMessage()"></input>
    <applet id="myApplet" code="MyApplet.class" width="400" height="100"></applet>And in the JavaScript file:function setAppletMessage()
      var msg = document.getElementById("msg").value;
      document.myApplet.setMessage(msg);
    }This is about all you really need to do. See how the Graphics object is no longer in your .js file?
    Note: You may run into other difficulties in getting this code to work because of browser, security, or some other pain-in-the-neck issues, but this is the idea.
    Eggbertx, I see you added a star to my first post and I think you should take that off because:
    1. <tt>Component</tt> is abstract... so you can not call the <tt>new</tt> operator.
    2. The call <tt>component.getGraphics()</tt> is not going to work either, because <tt>component</tt> was never created.

  • Calling Actionscript functions from HTML in Air?

    Arg... I feel like I am soo close - but something is not
    quite right...
    I am stuck on the communcation from Javascript back to
    Actionscript in an Adobe Air 1.5 app... (not flex).
    here is my Main():
    quote:
    public class Main extends Sprite {
    public var _as3Var:String = "testing";
    public function as3Function():void
    trace("as3Function called from Javascript");
    public function Main() {
    NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE,
    onInvoke);
    protected function onInvoke(e:InvokeEvent):void {
    NativeApplication.nativeApplication.removeEventListener(InvokeEvent.INVOKE,
    onInvoke );
    var app = new App();
    addChild(app);
    app.init(new ExternalContainer(), e.currentDirectory,
    e.arguments);
    Now, I simply want to either access _as3Var or as3Function()
    from my AppSandbox javascript... My HTMLLoader looks like this:
    quote:
    _html = new HTMLLoader();
    _html.useCache = false;
    _html.runtimeApplicationDomain =
    ApplicationDomain.currentDomain;
    _html.load(new URLRequest("sandbox/AirRoot.html"));
    And this is my javascript snippit:
    quote:
    Exposed.testAs3 = function()
    air.trace("Exposed.testAs3 called"); /* this works great */
    air.trace("runtimeVersion:"); /* this works great */
    air.trace(air.NativeApplication.nativeApplication.runtimeVersion);
    /* this works great */
    air.trace("seeing if I can get to AS3 params..."); /* this
    works great */
    air.NativeApplication.nativeApplication.as3Function(); /*
    this produces an exception: TypeError: Value undefined does not
    allow function calls. */
    What I am doing wrong?

    as3Function and _as3Var are members of Main, not the
    nativeApplication object.
    How you can reference your Main object depends on the
    relationship between Main and the HTMLLoader running the
    javascript. For example, if _html is a child of Main, you could
    call as3Function like this: window.htmlLoader.parent.as3Function().
    If _html is not a child of Main, then you can either create a
    static reference to Main in the Main class constructor:
    public static var mainInstance:Main;
    public function Main() {
    mainInstance = this;
    Or create a reference to Main in your JavaScript object when
    you create _html. If _html is created inside Main (so that this is
    the Main instance), then the following would work:
    _html.window.mainInstance = this;
    You could then call as3Function like this:
    window.mainInstance.as3Function();

  • Getting Error while calling Flex function from JavaScript

    Hi,
    I have an aspx page, which shows charts as per dropdown selection,
    I am using flex charts for flex.In aspx page, i am calling an mxml function using javascript.below is the code for javascript in aspx.
    Javascript  code in aspx page:
    <script type="text/javascript">     
    function callApp(formid) {
        try {
                var objectChart = document.getElementById("statisticsChart");
                alert(objectChart.id);               
                objectChart.myFlexFunction(formid,get('<%=HiddenDashboardWS.ClientID %>').value);
        catch (e) {
            alert(e.message);
    function getDropDownListvalue() {
        var IndexValue = $get('<%=FormDropDownList.ClientID %>').selectedIndex;
        var SelectedVal = $get('<%=FormDropDownList.ClientID %>').options[IndexValue].value;
        //  alert(SelectedVal);
        callApp(SelectedVal);
    </script>
    Html code where dropdown control is placed
    <asp:DropDownList CssClass="combo" ID="FormDropDownList" runat="server" AutoPostBack="false"></asp:DropDownList>
    <object id="statisticsChart" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
    height="220" width="680">
        <param name="src" value="../swf/DashboardStatisticChart.swf" />
        <param name="flashVars" value="" />
        <embed name="statisticsChart" src="../swf/DashboardStatisticChart.swf" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" height="220" width="680" flashvars=""></embed>
    </object>
    Mxml code:
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  backgroundColor="white" creationComplete="initApp();" >
    <mx:script>
      public function initApp():void {
    ExternalInterface.addCallback("myFlexFunction",myFunc);
      public function myFunc(s:String,wsurl:String):void {
         Formid.text = s;
         webService.wsdl = wsurl;
         Alert.show("webservice");
    //Getdata calls webservice and gets xml data    
    GetData();
    //showchart() will draw chart
                     ShowChart();
    </mx:script>
    </mx:Application>
    Above code works perfect in ie, but in firefox, it gives An error saying “chartObject.MyFlexFunction is not a function”.
    I am getting the object in javascript in all the browsers, but not the functions!
    Does anyone has worked with this?
    Any help will be highly appreciated.
    Regards,
    Nirav Patel

    Found the solution from here... http://74.125.153.132/search?q=cache:4BC9BY04B5EJ:livedocs.adobe.com/flash/8/main/00002201 .html+externalinterface.addcallback+not+working&cd=1&hl=en&ct=clnk&gl=in
    Hope it will help others...
    Regards,

  • Cannot call AS3 Function from JavaScript

    Hi,
    I am trying to call an ActionScript 3 function with JavaScript. The problem I cannot seem to get any of the browsers to trigger this AS3 function. The debuggers say that the function is undefined when I call it on the flash object. 
    What is supposed to happen is - the javascript function calls the AS3 function, and passes it an integer value.   That integer is then used to pull one of 20 swfs, and load that into the flash movie.
    Please let me know if you guys can think of anything that I can do to make this work!  I've been stuck for hours, and can't seem to make it happen.
    Here is my actionScript:
    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.external.ExternalInterface;
    var movies:Array = ["idle-ok.swf", "idle-good.swf"];
    // It first loads this "hello swf".
    var helloLoader:Loader = new Loader();
    var helloURL:URLRequest = new URLRequest("idleAvatar.swf");
    helloLoader.load(helloURL);
    addChild(helloLoader);
    var setAvatar:Function = loadAvatar;
    ExternalInterface.addCallback("callSetAvatar", setAvatar);
    // Then, this function should be called by JavaScript to load one of the other swfs.
    function loadAvatar(indx:Number){
        var url:URLRequest = new URLRequest(movies[0]);
        var ldr:Loader = new Loader();
        ldr.load(url);
        addChild(ldr);
    Here is my JavaScript:
    <script type="text/javascript">
    function callExternalInterface(val) {
              document.getElementById("loader").callSetValue(val);
    </script>
    Here is my embed code:
    <div>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="250" height="350" id="loader" name="loader">
    <param name="movie" value="loader.swf" />
    <param name="allowscriptaccess" value="always" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="loader.swf" width="250" height="350">
    <param name="allowscriptaccess" value="always" />
    <!--<![endif]-->
    <a href="http://www.adobe.com/go/getflashplayer">
    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
    </a>
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
    </object>
    </div>
    <a href="#" onClick="callExternalInterface(1)">CLICK</a>

    You don't appear to be calling any function in your actionscript.  The names between and within do not agree. 
    document.getElementById("loader").callSetValue(val);
    should be calling a function identified with the string "callSetValue" in your actionscript, but you only have a function identified with "callSetAvatar"  and the function associated with that on your AS3 side is specified to be setAvatar...
    ExternalInterface.addCallback("callSetAvatar", setAvatar);
    but you do not have a function named setAvatar, you have one named loadAvatar
    Here's a link to a tutorial that might help you to see how the functions are specified between javascript and actionscript using the ExternalInterface class.  It gets confusing so I suggest you copy the code to a word processing file so you can clearly highlight where they have the same language between them.
    http://viget.com/inspire/bi-directional-actionscript-javascript-communication

  • How can we call actionscript functions from js

    hi
    how can we call Action script function from js file . i
    tried ExternalInterface. add Callback() .but it throws an error .is
    there any other chance to call action script method .thnx in
    advance

    angadala,
    some people have found it is good to include the full
    qualification path, ie
    if (flash.external.ExternalInterface.available)
    flash.external.ExternalInterface.addCallback("ext_method_name",int_method_name);
    } // if (flash.external.ExternalInterface.available)
    There are also browser differences which affect how you find
    the Flex application object which are documented at
    http://www.adobe.com/livedocs/flex/3/html/help.html?content=passingarguments_5.html
    Richard

  • Call .xhtml file from javascript function

    Hi,
    Is there a way to call .xhtml page from javascript function???

    BalusC wrote:
    Yes there are some ways. But this question has nothing to do with JSF and certainly not with Java at all. Javascript is an entirely different language, although it has a similar syntax as Java (and unforunately also a similar name, they should never have renamed it from ECMAScript).I think ECMAScript is a renaming from JavaScript. The originally JavaScript was called LiveScript by Netscape. I've heard that the ECMAScript name was deliberately chosen to be unsexy.

  • Trying to call a function from a variable in Flex 4.0 ActionScript and need some suggestions

    I am attempting to build a site map in Flex. I have my links (or will have) in a database, along with a "link." On click from a datagrid, I have an event handler where I can get the link. However, everything I have tried to use won't call the function. Ideally, I would like to call a function from from my topLevel application, and I can do that using the mx.core.FlexGlobals.topLevelApplication call. Can anyone point a fairly new Flex coder in the right direction? Thank you.

    Here is the function on the group component (simplified): -- I got this from one of my google searches. The other was using the SWFLoader, but since this is in the same application, I didn't think it was as relevant. Plus, the SWFLoader used some references that I couldn't resolve.
    private function site_click(event:ListEvent):void {
      var sURL:String=list.dataProvider[event.rowIndex].link;
       var sCommand:String="mx.core.FlexGlobals.topLevelApplication." + sURL;
       this.[sCommand]();
    This yields the error message ReferenceError: Error #1059: Property mx.core.FlexGlobals.topLevelApplication.myths_click() not found on sitemap and there is no default value.
    Whereas this works fine:
    mx.core.FlexGlobals.topLevelApplication.myths_click();
    sitemap is my component name.

  • Calling PL/SQL from JavaScript

    Hi,
    I was wondering whether anyone has been able to successfully call a PL/SQL function from JavaScript and have the PL/SQL function return a result to the calling JavaScript function.
    What I am wanting to do is, depending on what the value returned from the PL/SQL function is, either enable or disable a button on a web form. This would be done before displaying the form. We are current using 9iAS 1.0.2.2.2a and running Portal 3.0.9.8.0
    Any ideas would be appreciated.
    Regards,
    Scott.

    Hi,
    We have managed to create a solution to our problem. I have the copied in the code just incase other people are interested in what we did. We did this through Oracle Portal using the Additional PL/SQL Code section. Please see below.
    is_user() is a PL/SQL function that checks whether the logged in user is a company user or client. It returns a VARCHAR2 of either "TRUE" or "FALSE".
    ... before displaying the form.
    declare
    lv_is_user varchar2(50) := is_user(portal30.wwctx_api.get_user);
    begin
    htp.p('<script language="JavaScript1.3">
    function getItemObj(form,target)
    var objname;
    //Loop through all elements in the form
    for(var j = 0; j < form.length; j++)
    objname = form.elements[j].name.split(".");
    if (objname[2] == target)
    return form.elements[j];
    function disableButton(form, btnName)
    var isUser = "' || lv_is_user || '" ;
    if (isUser == "FALSE")
    var btnObj = getItemObj(form, btnName);
    btnObj.disabled = true;
    </script>');
    END;
    ... after displaying the form.
    htp.p('
    <SCRIPT>
    disableButton(document.forms[0], "FORM_BTN");
    </SCRIPT>

  • How to call java function in javascript

    Hello Everyone,
    Can anyone tell me solution that:
    How to call java function in javascript?
    Thanks,
    VIDs

    You can't since Java is running on the server and javascript is running in the browser long after the Java side of things has finished executing. Assuming you're not talking about an applet here.
    But you can make calls back to the server through Ajax. All you need is something like a servlet on the receiving end which you can invoke through Ajax; from that point you can execute any Java code you want.

  • How to call JSP function from onClick Action

    Hi
    I am trying to call a jsp function, onclick of a checkbox. This jsp function will in turn connect to the database and gets related information. I dont want to submit the data inorder to avoid posting and getting of huge data. Is there a simple way to call a jsp function from the users onClick action.
    Appreciate anyones help!!!
    Thanks alot
    Joe

    So, i have to submit the form to call the jsp function. Basically yes.
    Sorry for the shortness of the answer, but I am pretty sure we have had this conversation (or one very much like it) before.
    Java/JSP runs on the server, generates an html page, and stops running.
    Javascript runs on the client in the web browser, once the page is loaded.
    You cannot call java code from javascript.
    The only way you can run java code again is to make a request - either by submitting a form, or clicking a link.
    If you don't want to refresh the current page, you CAN get tricky with javascript and multiple frames. You submit to another frame, and when it loads, it uses javascript onload event to call back and modify the main frame. Its tricky to get going, and very easy to break, so I don't normally recommend it.
    Good luck,
    evnafets

  • Calling JavaFX Script from JavaScript on mobile

    Hi,
    We are developing a application which would run on a mobile. We have to call javafxscript from javascript in this application. Is there a way to do this on a mobile application. I am able to do this for application running on browsers.
    Will javafx mobile application support this Calling JavaFX Script from JavaScript?
    Please share any information related to this.
    Regards,
    Sherlyn

    I doubt it (but I can be wrong!).
    javafx.stage.AppletStageExtension is only on the desktop profile.
    [Calling From JavaScript to JavaFX Script|http://javafx.com/docs/tutorials/javafx-javascript/] article states "+this functionality requires Java SE 6 Update 10 at minimum+" which seems incompatible with mobile usage.
    Beside, a quick Google search hints that JavaScript support on mobile browsers is weak or inexistent (depending on browsers).

  • How call Flash function from C++?

    Communication between C++ and ActiveX Flash object is
    adjusted. The ActiveX calls C++ functions. But how a call Flash
    functions from C++?
    I try so: v_flash is control variable of the ActiveX the
    container.
    A code: v_flash. CallFunction ("test");
    No effect
    How it to make?

    Hi David, Thanks for the response. I found this solution by
    following method:
    Flash code either in class or frame:
    ExternalInterface.addCallback("sendTextToFlash",
    getTextFromJavaScript);
    public function getTextFromJavaScript(user):void {
    trace(user);
    //Now whenever JavaScript function will be called from any
    HTML or back end language then it definetly call directly that
    flash function by following method
    //HTML Code
    function sendData(user){
    //alert("values coming "+user);
    SendDataToFlashMovie(user);
    function getFlashMovieObject(movieName){
    if (window.document[movieName]){
    return window.document[movieName];
    if (navigator.appName.indexOf("Microsoft Internet")==-1){
    if (document.embeds && document.embeds[movieName])
    return document.embeds[movieName];
    else {// if (navigator.appName.indexOf("Microsoft
    Internet")!=-1) {
    return document.getElementById(movieName);
    function SendDataToFlashMovie(user) {
    var flashMovie=getFlashMovieObject("myFLA");
    flashMovie.sendTextToFlash(user);
    Now HTML or back end language has just need to call
    sendData(
    value)
    I think its the right way, but if there is any other short
    method like just call the function name from HTML and that directly
    respond to Flash as per function name, then please let me
    know.

  • Calling a function from a DLL, exectution in background mode.

    Dear Experts,
    We have created an ABAP report the calls a function from a DLL file. If the report is executed in on-line mode the program calls and executes the function from the DLL, but if the ABAP programa is executed in background mode it doesnt calls the DLL function.
    Do you know a way to solve the problem when executing in background mode?
    Best regards.
    Antonio

    Hi Gabriel,
    Let me explain in details about my DLL function.
    We are importing the business partners from legacy system into the SAP CRM system, so at the moment we created the BP master data via BAPI, I get the name of the BP and this moment I call the function in the DLL file. I export the parameter name and I receive back a simplified string with the name reduced to a code. This code I get back from the dll it is insert in a Z table, so there is no interaction in the screen, all must be executed in background mode, because there are a lot of business partners to be converted in SAP system.
    I am sending my code for your considerations.
    Instancia a DLL
      CREATE OBJECT dll 'MTCODE.CPFONET'.
      IF sy-subrc NE 0.
        RAISE without_dll.
      ENDIF.
    Move para a tabela interna IT_NAME os valores recebidos na TI_NAME
      it_name[] = ti_name[].
    Para cada registro importado
      LOOP AT it_name.
        CLEAR v_string_ret.
        wa_matchcode-zregid     = it_name-zregid.
        wa_matchcode-name1_text = it_name-name1_text.
        v_string = it_name-name1_text.
        CONDENSE  v_string.
        TRANSLATE v_string TO UPPER CASE.
        CALL METHOD  OF dll 'SetNome' EXPORTING #1 = v_string.
        CALL METHOD  OF dll 'ExecMatch'.
        CALL METHOD  OF DLL 'GetMCData' = v_string_ret.
        FREE OBJECT dll.
      Preenche os campos do match-code de acordo com o retorno da DLL
        SPLIT v_string_ret
        AT '|'
        INTO wa_matchcode-zparmcln
             wa_matchcode-zparmcfn
             v_empty
             wa_matchcode-name_first
             wa_matchcode-name_last
             wa_matchcode-namemiddle.
      Adiciona o registro com o match-code correspondente na TE_MATCHCODE
        APPEND wa_matchcode TO te_matchcode.
      ENDLOOP.

  • How can I call a function from a procedure

    I have a function named: f_calc_value which return the variable v_result. This function is part of a package.
    How can I call this function from a new procedure I am creating?
    Thanks

    or refer this theread....calling function from procedure

Maybe you are looking for

  • How do I transfer contacts from iPhone to Android?

    I recently moved from iPhone to Android and now want to transfer my contacts over. However having reviewed some similar queries on this discussion board I still cannot do it. I have seen comments to go into iTunes and select the sync contacts with dr

  • Report/query result acting as a link to a PO document

    Hi, Is it possible to have T0.[U_z1] (which is always the PO docnum) from the query below to act as link (i.e: orange arrow) so by clicking it the PO would open ? SELECT T0.[DocNum], T0.[DocDate], T0.[U_z1] as 'nr.ZZtrans', T0.[U_Transport_nr_rej], T

  • My Iphone5 screen is black and when I plug it in, all I get is the Apple logo... flashing

    My Iphone 5 has a black screen and when I plug it in, all I get is the Apple Logo, which flashes.  Help!

  • Brand new, seeking advice

    Hello everyone,l have been lurking on these boards for the past two months or so, taking as much advice as I could find. After several years of not caring about my future or my credit score I have recently decided to take charge of my life. In the pa

  • Call ww... function

    Can someone tell me how to call, from JSP, a stored procedure from ww... package with "output parameters" or a function and to take its return value