Passing in arguments of js-> as3 via ExternalInterface

Is it possible to use javascript to call a method in as3 and pass in an object argument? This would act as a setter in a way...

Thanks in advance for any advice!

You would use ExternalInterface.addCallback("IsStatic",IsStatic) to save a JS function call:

// AS
// register call from Javascript
ExternalInterface.addCallback("callFromJS", callFromJS);

// display the message from Javascript
function callFromJS(s:String):void
{
    textfield.text = s;
}

Call from the JS:

// JS
flashObject.callFromJS("Hello from JS");

You may need to define true allowScriptAccess in the HTML embed code.

Tags: Adobe Animate

Similar Questions

  • Is it possible to pass an argument to the function triggered by an event handler?

    Hi all
    Try to migrate my way of thinking in AS2 to AS3/CS4.
    OK, I have 2 buttons on the stage. Each button almost did the same thing, so I want to create a unique function, and each button calls this function even (we'll name this function 'Navigate')... However, the function will have to end up doing something different dependent on which button was clicked.
    If, previously, in AS2, I would have added the code on the buttons themselves with methods we (release) (see the SAMPLE CODE 1)

    Thus, each button calls the function efficiently navigate and transmits a different image to the function tag.
    Now, I try to recreate this feature in AS3. As you know, it (release) has been abolished (still do not know why), but we must now use event handlers, so I'll try to find a way to pass a different image to the function label argument to navigate. Currently, I can achieve that by using a switch statement to test which button has been clicked and act accordingly (see the SAMPLE CODE 2).

    In this simplistic example, this works very well, but in the real world, I have more than 2 buttons and the function navigate would probably much more complicated...
    So I would be able to pass an argument (as in the AS2 example) to the function to navigate... maybe in the addEventListener() method? I tried, but got compile errors (see the EXAMPLE CODE 3):

    The issue of the $ 1 Million:
    Is it possible to pass/change dynamically an argument to a function that is triggered by an event listener? (Or is the event that triggered the function the only argument you have?)
    If this is not possible, I would like to hear how you people it would handle (other than to have a switch with 12 cases in there)?

    I found a few solutions that I'll post below for prosperity...

    You can create a dictionary indexed by the targets of future events and store information in there you want to associate with them. Then the Navigate function check that the dictionary to get its parameters:

    Code.
    Button1.addEventListener (MouseEvent.CLICK, navigate, false, 0, true);
    Button2.addEventListener (MouseEvent.CLICK, navigate, false, 0, true);

    var buttonArgs:Dictionary = new Dictionary();
    buttonArgs [Button1] = "FrameLabel1";
    buttonArgs [Button2] = "FrameLabel2";

    function Navigate(e:MouseEvent):void {}
    gotoAndStop (buttonArgs [e.target]);
    }

    This to me, is about the same amount of work than writing a long, but a bit more elegant switch statement, I guess.

    I had a little trouble understanding the following solution, because I did not quite understand important information about event listeners. The addEventListener () method requires a function as the 2nd argument passed to it.
    It didn't quite click on until someone reminded me: Navigate is a function... Navigate("FrameLabel1") is a callfunction...

    So by writing simply navigate, I'm not actually calling the function when calling the addEventListener method, I'm just providing the event with a reference the name listener. Then, when the listener is triggered, the listener will call (and pass a MouseEvent argument to) navigate the function.

    Conversely, by writing Navigate("FrameLabel1") as 2nd argument, the event listener trys to run the function navigate both the addEventListener method is instantiated. And, since then, in this example, the function navigate returned as ": Sub" a compilation error would occur because as I said, an event listener requires a function as 2nd argument data type. This would be essentially as written addEventListener (MouseEvent.Click, Sub, false, 0, true)
    However, there is a way to get around this... basically, instead of setting the function navigate as returning an empty data type, you define a function to return data type and then nest another function (which actually contains the actions you want to run) on the inside.

    Button1.addEventListener (MouseEvent.CLICK, Navigate ("FrameLabel1"), false, 0, true);
    Button2.addEventListener (MouseEvent.CLICK, Navigate ("FrameLabel2"), false, 0, true);

    function Navigate(myLabel:String):Function {}
    return function(evt:MouseEvent):void {}
    gotoAndStop (myLabel);
    }
    }

  • How to pass an argument of javascript to java extension

    Hello, I have an application running with a Java Extension.

    For the course of time, I only call some java extension methods (ScriptableFunction, but now, I have to pass the variable javascript (arguments) to the extension.

    I call a method with:

    // In: public final class MyCamera extends ScriptableFunction
    
    public Object getField(String name) {
    
        if (name.equals("getImage")) {
         return callGestorCamera.pushUICameraSnapshot();
        } 
    
        return new String("do nothing");
    }
    

    and javascript :

    function getImage() {
        var name = mycamera.camera.getImage;
        return name;
    }
    

    and run correctly.

    But now I have to pass one argument, as some URL, and I don't know how to do.

    I try to move the handful of Java class to Javascript, something like this:

    // In: public final class MyCamera extends ScriptableFunction
    
    public Object getField(String name) {
    
        if (name.equals("getImage")) {
         return callGestorCamera.pushUICameraSnapshot();
        } 
    
        if (name.equals("getObject")) {
         return callGestorCamera;
        }
    
        return new String("do nothing");
    }
    

    and javascript :

    function setUrl(url) {   var handle = mycamera.camera.getObject;        handle.setUrl(url);
    
        return true;}
    

    but is not running and try:

    mycamera.camera.getObject.setUrl(url);
    

    but does not work.

    What is the way?

    Thank you!

    I believe that the Extensions lab shows how to pass a parameter to a function... For example, he spends the duration of the vibration.

    http://NA.BlackBerry.com/eng/developers/devbetasoftware/Lab_Widget_Extension.zip

  • Passing multiple arguments to a CFC

    Currently, I connect to Coldfusion with a RemoteObject and pass a single argument. Is it possible to pass multiple arguments? Just add a comma separated by the argument list in the parens competence does not seem to work.

    "" < mx:Application xmlns:mx = ' http://www.adobe.com/2006/mxml ' layout = "absolute" creationComplete = "initApp (event)" >

    -Block of Script.

    private void initApp(e:Event):void {}
    chartmth_RO.qMonthlyUsage (200804);
    }
    ----
    < mx:RemoteObject id = "chartmth_RO" showBusyCursor = "true" destination = "ColdFusion" source = "usagecenter_local.cfc.charts_usage_mth" >
    < name mx:method = "qMonthlyUsage" result = "get_Result (event)" / >
    < / mx:RemoteObject >

    Once more I am kicking. You can pass multiple arguments in a CFC using a comma separate list the key is to encapsulate each string between apostrophes. So let's say I want to pass the arguments saleschart, fiscal year 2008, 300. The inside of my call parens jurisdiction would look like ('saleschart', 'exercice2008', 300).

    I love it when an answer is revealed, but I hate when it seems so simple.

  • How to pass an argument to a standalone java class JDeveloper

    For the experienced:

    In JDeveloper when you write a java class with a main() method that takes no arguments, you just click with the right button on the java file and choose run to run the program. But suppose the main() method takes arguments, how to move your arguments to the program? This is especially a problem I use the studio version of JDeveloper (10.1.3.4 and 11.1.1.3 Versions) that each uses the version of the JDK included with, rather the JDK (which is yet another different version) installed at the level of the OS on the PC.

    Thanks a lot for your help!


    Newman

    Hello

    If you mean how to pass arguments in JDeveloper:
    Tools > Project Properties > run/debug > change the default run Configuration (or create a new) > settings start > program Arguments - here you can set arguments

    Kind regards
    Branislav

  • Problem with AS3 &amp; quot; ExternalInterface.call("saveglobalscore",score) &amp; quot; in Internet Explorer

    Hello

    Explain how the page is set up:

    I have a HTML page with 2 different movies Flash AS3.

    The first flash movie is the main entertainment and is located in the middle of the screen with a large background image defined in the body of the HTML.

    The second flash movie spans 100% width/height of the size of the screen and acts as a black fade > invisible.

    What I'm doing:

    Once the second Flash animation has gone from black to invisible it calls a JavaScript function on the HTML page to hide the div element, the second flash movie is integrate in (it's like the first flash movie displays a set of input boxes, which the user must be able to type-which will not be able to click on if there is another flash animation that just overlap the first film).

    My initial solution:

    In the second Flash movie is the following code:

    ////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
    Stop();

    This will load the API needed to communicate with external entities
    to import flash.external.ExternalInterface;

    call the JavaScript function
    ExternalInterface.call("saveglobalscore",score) ('myJavaScriptFunction');
    ////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////

    .. .and it works fine in Mozilla Firefox/Safari. The actionscript code successfully the JavaScript function in the HTML page and this JavaScript function simply calls (to this poster from the scene an alert() message to show that it has been called successfully).

    Problem with IE:

    But, at the time when I try this in Internet Explorer, I get an alert() message but a JavaScript error message that says:

    ////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
    Code: Select all
    Line: 1
    Char: 106
    Error: 'null' is null or not an object
    Code: 0
    ////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////

    As you would expect I am totally confused as to what could be the problem.

    It's really urgent because it is a living project which must be completed immediately, any help you might have would be greatly appreciated!

    Kind regards

    Select this option.

    GWD salvation,

    Who did it! :)

    I applied the attribute id = "fTrans" to the tag and IE worked well.

    I disparage me my brain one, thank you very much!

    Kind regards
    Mark

  • problem passing of arguments to plsql block with a lot of sql queries

    HELP PLZ!

    FILE = $(PWD)

    EMP_FAIL = $(awk-F '=' ' / ^ EMP_FAIL_RECORD / {printf $2}' DBConnectionParameters/DBConnectionParameters.properties)

    HR_FAIL = $(awk-F '=' ' / ^ HR_FAIL_RECORD / {printf $2}' DBConnectionParameters/DBConnectionParameters.properties)

    sqlplus-s "${USER_NAME}/${PASSWORD}@${HOST_NAME}:${PORT}/${SERVICE_NAME}" < < EOF

    -a lot of queries and other things

    HR_FAIL$ @ReportOperation/HR_Err_Spool.sql $FILE <-arguments

    EMP_FAIL $ @ReportOperation/Emp_Err_Spool.sql $FILE

    EXPRESSIONS OF FOLKLORE

    / * The above used to work * /.

    sqlplus-s "${USER_NAME}/${PASSWORD}@${HOST_NAME}:${PORT}/${SERVICE_NAME}" < < EOF

    -just 2 queries below

    HR_FAIL$ @ReportOperation/HR_Err_Spool.sql $FILE <-arguments

    EMP_FAIL $ @ReportOperation/Emp_Err_Spool.sql $FILE

    EXPRESSIONS OF FOLKLORE

    / * Works one above * /.

    HR_Err_Spool.SQL

    SET POSITION OFF FEEDBACK OFF ECHO OFF PAGESIZE 0

    coil & 1 Add;

    Select GID | «, » || Display_Name | «, » || Email_Address. «, » || Country_Code | «, » || City | «, » || Department | «, » || Practice | «, » || Designation | «, » || Status_in_AD | «, » || Start_date | «, » || End_date | «, » || Person_Type | «, » || Err_temp_emp_hr status;

    spool off;

    You SET DEFINE OFF then never back down it on before running reel & 1 Add.

    If the DEFINITION is disabled the & 1 is not evaluated as a parameter.

  • Passing of Arguments to the Bean with EL method

    Hello:

    11.1.2.3 Jdev

    I created the following managed Bean (see below) in a taskflow with scope of Backing Bean. I can call fieldColor ok with
    EL as in #{backingBeanScope.CheckTimezone.fieldColor}-> works ok

    But now I want to pass a string value to the testDate method and returns a string. What is the El to make this work?
    I tried:

    #{backingBeanScope.CheckTimezone.testDate ('someString')} but it does not work and said testDate is not recognized.

    What is the correct way to call this method by passing a string arg?

    Are there articles that explain this?

    Thank you very much...





    public class CheckTimezone {}
    private String fieldColor = "in late';

    public CheckTimezone() {}
    Super();
    }

    {} public void setFieldColor (String fieldColor)
    this.fieldColor = fieldColor;
    }

    public String getFieldColor() {}
    System.out.println ("called getFieldColor");
    Return fieldColor;
    }

    public String testDate (String subsist) {}
    System.out.println ("called testDate, passed in value is:" + stand);
    Return fieldColor;
    }


    }

    In case, you can create a property testDate in your bean that returns a map object.

    public class CheckTimezone {}
    private String fieldColor = "in late';
    Private final FunctionMap functionMap = new FunctionMap();

    public CheckTimezone() {}
    Super();
    }

    public String getTestDate (String subsist) {}
    Return functionMap;
    }

    Internal class implementation of the map
    Public NotInheritable class final FunctionMap implements {map
    private FunctionMap () {}
    Super();
    }
    public int size() {}
    return 0;
    }
    {} public boolean isEmpty()
    Returns false;
    }
    {} public boolean containsKey (Object key)
    Returns true;
    }
    public boolean containsValue (Object value) {}
    Returns true;
    }

    Write your logic here
    public Object get (Object date) {}
    System.out.println (date);
    }

    public Object put (Object key, Object value) {}
    Returns a null value.
    }
    public Object remove (Object key) {}
    Returns a null value.
    }
    {} public void putAll (map m)
    }
    Public Sub clear() {}
    }
    {} public Set keySet()
    Return Collections.emptySet ();
    }
    public Collection values() {}
    Return Collections.emptySet ();
    }
    {} public entrySet() Set
    Return Collections.emptySet ();
    }
    }

    }

    In your page jspx - #{backingBeanScope.CheckTimezone.testDate ['someString']}

  • Pass an argument of jsx external to the html Panel?

    Hello world

    Can you please tell me if it is possible, somehow, to listen to the event of jsx externally in html Panel? What I'm trying to do is to move a JSX argument to the HTML Panel and update

    the Panel with her.

    Thank you very much

    Sergey

    Hello Sergey!

    What I was suggesting private to you (I report it here for the sake of others) is to use the technology of CEP5 as soon-to-be-released: http://blogs.adobe.com/cssdk/2014/04/introducing-cep-5.html

    Especially, the part that says:

    Call of ExtendScript in HTML DOM: most Adobe applications currently supported (including but not only CC of Photoshop and Illustrator CC) will include a new ExternalObject that provides an API that allows developers to send ExtendScript events in JavaScript/HTML5

    But we must wait for the next update of the CC apps to support!

    Concerning

    Davide Barranca

    ---

    www.davidebarranca.com

    www.cs-extensions.com

  • AS3 via an Fms Server

    This is a mutual question as3 and fms, I'm not sure - an experienced user can help in this forum, but...

    In my flv file, I have 500 hundred videos of small size (20 seconds if - 0,80 MB wise bytes) in the library. In a test, randomly tese Inc. 6 come out on the screen and since this is a test, if you choose the correct video, the next question (another 6 videos randomly come and so on...)

    I have 2 questions here

    1. my swf works well with 20 videos (flv playback) in the library, but when I filled the library with 500 of them, is there a problem of size possible because of the ability of libraray (I think that the scene is not a problem because only 6 videos are available on the scene every time)

    2. If I publish this swf in the net and use a fms server to make it possible that everyone can use the swf and videos at the same time.

    what capacity I'll choose as -? How many people at the same time. There are options like 100 people-300-500 people at the same time. But in brief in my library I have videos and randomly 6 have500 on the scene.

    Thnx...

    If you import these short video files in your Flash movie, you don't need to use a Flash media server. In any case, you probably don't want import 500 video files in your movie. At the very least, that will make a unique 400 MB file that your user will have to handle the download.

    If you only 6 videos at the same time, you can randomly select 6 to view, download and use. Continue to download 6 at a time as needed as the program continues.

    The number of users should have little or no effect on the ability of the server to meet the demand. Each file is small and calling to 6 at a time won't cause tension on a server. Yet once, there is no need of a Flash media server.

  • Passing parameters to and from AS3 PHP

    Hi, I'm looking for the best methods pass variables to a MySQL and receive this database variables as well.  Could someone point me in the right direction in best practices to achieve this?

    Use the urlloader class to call a script server which interacts with your database.

  • Pass the url of the AS3 fla class

    I have a class that works with an external swf with play, pause, and slider. Now that I have everything working, I would like to be able to pass the URL of the SWF file that is external to the main fla As class. I managed to use a 'set' inside the class to retrieve the name, but it is not apparently trigger until after the external SWF is loaded. The following code snippets:

    CntlClass:

    public var loader: Loader;
    private var _urlName:String;

    public void CntlClass()
    {
    loader = new Loader();
    loader.contentLoaderInfo.addEventListener (Event.COMPLETE, movieLoaded);
    Loader.Load (new URLRequest (_urlName));

    .

    .

    .

    public function set urlName(value:String):void
    {
    _urlName = value;
    }

    Main FLA file - other than a controller (cntl_mc) that contains a "play" button, a pause button and a slider, the only thing in the FLA file is this code in the first frame:

    cntl_mc.urlName = "extswf.swf";

    You must remove the load() your Builder.  Otherwise, you must call your setter before your Builder runs - a guaranteed error.

    so, have your setter call a function that executes your load() method

  • Problem in passing several Arguments for simultaneous program

    Hello

    I need to pass two stamped in my simultaneous program

    but I am facing problem while adding the second parameter in the code below

    Please suggest how to pass several parameters for the simultaneous program
        Vector cpArgs = new Vector();
        cpArgs.addElement(shipmentId);
        cpAgrs.addElement(addId);
        System.out.println("Args"+ cpArgs);
    It's my submission of application code
        public int submitRequest(String shipmentId, String addId) throws Exception {  
        try {
          OADBTransaction tx = (OADBTransaction)getDBTransaction();
        java.sql.Connection pConncection = tx.getJdbcConnection();
        ConcurrentRequest cr = new ConcurrentRequest(pConncection);
            cr.addLayout("XXAPL", "XXAPLPORMSD", "en", "US", "RTF");
        String applnName = new String("XXAPL"); 
        System.out.println("ApplName"+ applnName);
        String cpName = new String("XXAPLPORMSD"); 
        System.out.println("Concc Name"+ cpName);
        String cpDesc = null;
        Vector cpArgs = new Vector();
        cpArgs.addElement(shipmentId);
        cpAgrs.addElement(addId);
        System.out.println("Args"+ cpArgs);
         
            int requestId = cr.submitRequest(applnName, cpName,cpDesc, null,  false, cpArgs);        
    
        tx.commit();    
    
        return requestId;
    
        } 
         
        catch (RequestSubmissionException e) {
        OAException oe = new OAException(e.getMessage());
        oe.setApplicationModule(this);
        throw oe;
    
        }
            catch(Exception exception)
            {
            throw OAException.wrapperException(exception);
            }
    
        }
    Krishna

    I did most of the changes. IAM do not know why the error is come

    This is the reason why...

    It should be cpA rg s

    NOT

    cpA gr s

    Thank you
    -Anil
    http://oracleanil.blogspot.com

  • Pass arguments of variable length to an another variable length arguments

    Do not pass an argument of variable length to another argument of variable length

    For example

    public void call(name:String,..._params):Object

    {

    ExternalInterface.call("saveglobalscore",score) (name, params);
    }

    call ("test", "param1");

    "param1" is considered to be an argument with the type of array in the second function of «call», but is what I want to treat it as an argument as a string.

    The result is:

    < call name = 'test' returntype = "xml" > < arguments > <table > <property id = '0' > < name String > < / string > < / property > </ array > </ arguments > < / call >

    But what I want is

    < call name = 'test' returntype = "xml" > < arguments > < String > name < / String > < / arguments > < / call >

    I have to do is:

    public void call(name:String,..._params):Object

    {

    If (params.length == 1)

    {

    ExternalInterface.call("saveglobalscore",score) (name, params [0]);

    } Else if (params.length == 2)

    {

    ExternalInterface.call("saveglobalscore",score) (name, params [0], params [1]);

    } Else if (params.length == 3)

    {

    ExternalInterface.call("saveglobalscore",score) (name, params [0], params [1], [2] params);

    } else

    throw new Error ("I'm crazy");

    }

    This is a terrible solution, if it no work around?

    The compiler must can handle this situation.

    Try:

    public void call(name:String,..._params):Object

    {

    params.unshift (Name);

    ExternalInterface.call.apply (ExternalInterface, params);

    }

    Alex Harui

    Flex SDK Developer

    Adobe Systems Inc..

    Blog: http://blogs.adobe.com/aharui

  • How to pass the object as a parameter in AS3?

    I get the impression that the non-static objects passing is not allowed in AS3. I never had a problem with that in AS2. Am I correct in this understanding?

    If Yes, do you know what is considered a best practice regarding pass non-static objects as parameters? Is not a good practice? Thank you!

    Ooops nevermind, I got the argument name of past typed exactly as the name of the class, that was the problem.

    function(passed:passed) = boo boo

Maybe you are looking for