Calling Javascript in Flex

Hi
I have a mxml file that has a button control
<mx:Button id="toggle" label="Test" click="ToggleButton()"
/>
When I click on the button I want to call the javascript
function. So in the mxml script I have
public function ToggleButton(): void
var f:String = "JSToggleButton";
var m:String = "this works";
var check:String;
if(ExternalInterface.available)
ExternalInterface.call(f,m);
check = "true"
else
check="false";
trace(check);
]]>
Now I created a text file by rightclicking on the assets(The
folder i created) folder in project and then new-->File.
I have written my javascript in that file and named it
JavaScriptToggle.html
This file has the following code
<SCRIPT LANGUAGE="JavaScript">
function JSToggleButton(m)
alert(m);
</SCRIPT>
It does not seem to show the alert box but the trace shows
true for ExternalInterface.available.
Am I missing anything important?????
I am completely new to flex. So it might be simple to most of
them. Please bear with me.

quote:
If I have a project named Test does this mean that I have to
include my Javascript in the bin folder's Test.html file?
Yes, so somewhere in Test.html you will have to have that
javascript function. But remember that flex builder will recreate
the Test.html file everytime you rebuild and you will lose any
changes you make to that file directly. So make your alterations to
the html-template/index.template.html file and it will always
recreate your Test.html with that code included.
So just open up html-template/index.template.html and place
between the head tags
&lt;script language=&quot;javascript&quot;
type=&quot;text/javascript&quot;&gt;
function JSToggleButton(m)
alert(m);
&lt;/script&gt;
Then everything should hopefully be working

Similar Messages

  • Calling Javascript from Flex through FAB

    What's the standard way of calling JavaScript functions from
    Flex through the FA Bridge?
    i.e. is there a new way other than navigateToURL or
    ExternalInterface.call()
    Most of the examples I've seen are scripting Flex from
    JavaScript, not the other way around.
    Thanks.

    Hello,
    You need to register the JavaScript function as a callback to
    a Flex action. You can do this from javascript in a function that
    gets called when the flash movie has finished loading. Then, when
    the Flex event is triggered it will execute the JavaScript
    function.
    Hope this helps,
    Cristian

  • How to send xml to javascript from flex?

    Hello,
    I am using Flex Builder......I read blogs and wonderful tutorials on adobe website. But I found that I can only have data from Flex to script placed within main.template.html file.....when i tried to get same data by in my other .html or .aspx page, it did not work. Another thing I noticed in following tutorial
    http://blog.flexexamples.com/2008/03/09/calling-javascript-functions-from-your-flex-applic ations-using-the-externalinterface-api/
    is that we placed <iframe> in our html page to host flex object instead of using <object> tag etc.
    Please just let me know how to do very same thing as defined in tutorial but by hosting out flex object using <object><embed> tags etc and how to get data into our .html or .aspx page rather putting javascript (to receive data) in main.template.html file generated by Flex Builder...???

    Thanks for replying,
    Now I am facing another problem....I have added a script tag in index.template.html file that also contains other useful code used in my aspx page. I wanted to have that reply on my aspx page. So I placed all the script in a Core.js file and also the recieving method from flex in same Core.js file. I thought this way i will be able to access data coming from flex project to my aspx page. But something strange is happening, when i run .html file in bin-debug folder it fires receiving method placed in Core.js........but when I host that flex project .html file in my aspx page, it is not firing method. And also not firing when I run .html in bin-release folder....what am I doing wrong?

  • IPad = webStageView = HTML = call javascript function thru Flash

    Has anyone loaded a HTML file thru webStageView, and then been able to call javascript functions embeded in the HTML through flash.
    I've seen references to using webStageViewBRIDGE but I think that has been depreciated.
    Below is a link to a Adobe tutorial doing this with the htmlLoader class and FLEX.
    Cross-scripting PDF content in an Adobe AIR application
    http://www.adobe.com/devnet/air/flex/quickstart/articles/scripting_pdf.html
    If anyone has successfully been able to do this on the iPad, could you explain how it's done or provide a link to some documentation.
    Thanks...

    Stagewebviewbridge is a 3rd party library (not an official Adobe product). It looks like it is still supported. The technique described should work even if the library isn't being actively developed.
    http://code.google.com/p/stagewebviewbridge/wiki/Communication
    Also, note that most techniques which use the HTMLLoader class will not work with the StageWebView class -- they are entirely different beasts. (Well, to be precise, on desktop computers, StageWebView uses the same Webkit code, but the interface to it is still very different.)

  • Java Applet call javascript problem

    Hi I have a web page as follow and embedded a applet. The applet call the java script, and instead of showing an alarm, the browser show the javascript code. Is that strange ? Any suggestion for this problem.
    HTML:
    ================================================================
    <HTML>
         <HEAD>
         function ShowEmbd()
              alert("Test Applet call Javascript");
         </SCRIPT>
         </HEAD>
         <BODY>
         <FORM NAME="AppletEmbdStart">
              <OBJECT classid="clsid:48B2DD7B-6B52-4DB0-97C9-ECB940113B47" id="CIVON_DEmbdObj" width="0" height="0"></OBJECT>
              <APPLET code="MyApplet.class" width="0" height="0"></APPLET>
         </FORM>
         </BODY>
    </HTML>MyApplet.java
    =========================================================================
    import netscape.javascript.*;
    public class MyApplet extends javax.swing.JApplet
         private JSObject m_win = null;
         private JSObject m_doc = null;
         public void init()
              getJSWin().call("ShowEmbd", null);
         private getJSDoc()
              if(m_doc == bull)
                   m_doc = (JSObject) getJSWin().getMember("document");
              return m_doc;
         private JSObject getJSWin()
              if (m_win == null)
                   m_win = netscape.javascript.JSObject.getWindow(this);
              return m_win;
    }The page was load and it should call the applet MyApplet. The MyApplet should do the init() method and call the Javascript "ShowEmbd()", BUT, instead of show alert from ShowEmbd(), the browser show the code of ShowEmbd() itself ...... It did not run the javascript and shows the alert ??
    The browser shows a message from status bar "The applet not initial" ???? why ???
    Can anyone help ?!

    On first look:
    I am not sure about the Object Tag, but the Applet Tag requires the MAYSCRIPT attribute before Java can call Javascript.

  • How to call javascript function in back bean of jsf

    hi,
    i am trying to call java script function in back bean but not done. Is there any code for call javascript function in bean file.

    Java runs at server side.
    JSF produces HTML output.
    Server sends HTML output to client.
    Java stops running.
    HTML runs at client side.
    JS starts to run in HTML.
    Clear? Java is a server side language. JS is a client side language. To run JS using JSF, simply print it out to the HTML so that it get invoked when the HTML runs.

  • How to call webservice using flex?

    Hello,
    i want to call webservice in flex.i tryied following code.but it is not giving correct response.what is wrong with this code?
    can anybody tell me ,how to call webservice in flex?
    Code:
    <mx:Script>
            <![CDATA[
    public function button1_clickHandler(event):void
         ws.returnRecord(para1,para2);//i am sending two parameter to returnRecord service here
    public function remotingCFCHandler(event:ResultEvent):void
    trace(event.result);
    ]]>
    </mx:Script>
    <mx:WebService
         id="ws"
         wsdl="http://localhost:8500/flexapp/returnusers.cfc?wsdl">
        <mx:operation name="returnRecords" resultFormat="object"
         fault="mx.controls.Alert.show(event.fault.faultString)"
         result="remotingCFCHandler(event)"/>
    <mx:Button label="Go" fontWeight="bold" click="button1_clickHandler(event)"/>

    Hello sir,
    i got following reply:
    <returnRecordResponse  xmlns="http://xyz" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <returnResult>Error_request</returnResult>
    </returnRecordResponse>
    but correct response is
    <returnRecordResponse  xmlns="http://xyz" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <returnResult>Success</returnResult>
    </returnRecordResponse>
    can you tell me correction in the code which i have put on the forum?or tell me other way to call webservice?

  • How to call javascript function from PL/SQL procedure

    Can anybody advice me how to call javascript function from PL/SQL procedure in APEX?

    Hi,
    I have a requirement to call Javascript function inside a After Submit Process.
    clear requirement below:
    1. User selects set of check boxes [ say user want to save 10 files and ticks 10 checkboxes]
    2. user clicks on "save files" button
    3. Inside a After submit process, in a loop, i want to call a javascript function for each of the file user want to save with the filename as a parameter.
    Hope this clarify U.
    Krishna.

  • WAD: Add variable to a called javascript function on button group item

    Hi All,
    I need your expertise regarding the following problem:
    To increase performance, I've decided to hide all analysis tables. To set these tables to visible, there is a button to switch the state for each table.
    Because this function is needed for each table, the function has two parameters for the analysis item name and the new state.
    Unfortunately, I get an useless error message after calling the function.
    The function in script item looks like
    function switchTable(itemName, newState)
    The function is started by a button of a button group item as javascript and the following script function
    switchTable('ANALYSIS_ITEM_1', 'VISIBLE')
    If I enter a without parameters, that will call the function with these parameters, it works.
    But if i try this directly from the script function in the button parameters, the function will be called correctly, but an error occurs and the analysis item wasn't displayed or the sendCommand wasn't processed completely.
    I hope there is a way to call javascripts by a button with variables, otherwise I would have to create many functions with only an other item_ref.
    Many thanks in advance and points of course for any help.
    Regards,
    Tobias

    One short note:
    It's possible to trigger the same function by an html input form button with onlick switchTable('ANALYSIS_ITEM_1', 'VISIBLE')
    and this works.
    Has anyone an idea what's the problem with a normal button item of the button group item?
    Another possibility is a menu item. The functions were called, but errors were shown.

  • Calling javascript from a button

    Good morning everyone!
    I need to add a message box that asks the user a confirmation to delete information. So I want my delete button to call the javascript necessary to confirm the delete and then delete.
    My problem is in calling the javascript. I'm able to do so by using an image for my button and in the image attributes add:
    onclick="javascript:confirmDelete('Are you sure you to delete?');"
    This works perfectly, except for one thing: I don't want to use an image for the button. It doesn't fit with the rest of the application.
    I know it can work, because Oracle is using it on this page:
    http://apex.oracle.com/pls/otn/f?p=37719:8:3069181226556730::NO:::
    So how can I call my javascript from an ordinary button?

    I have a related question:
    How can I access the BROWSER_LANGUAGE in javascript? With my method of calling javascript, I didn't find a good way to pass variables to the function that I call.

  • Calling webservice from Flex?

    Hi,
    I get the error when I call webservice from Flex.Can you tell
    me why this happen?
    Thanks
    Mark
    [RPC Fault faultString="Security error accessing url"
    faultCode="Channel.Security.Error" faultDetail="Destination:
    DefaultHTTP"]
    at mx.rpc::AbstractInvoker/
    http://www.adobe.com/2006/flex/mx/internal::faultHandler()
    at mx.rpc::Responder/fault()
    at mx.rpc::AsyncRequest/fault()
    at DirectHTTPMessageResponder/securityErrorHandler()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/redirectEvent()

    I think this means that the source of the web service does
    not have a crossdomain.xml file on it allowing access from your
    site. Try adding one to the root of the server and see if that
    fixes the problem.
    hth,
    matt horn
    flex docs

  • How to call javascript function in Flash

    Please help...
    I have a site that run multiple of domain for example
    Domain (A): raymond.com
    Domain (B): raymond.ca
    The problem is this.. when (B) html page load the flash file
    that locate at (A) it load but non of the buttons work which call
    javascript function using getURL("javascript:showpopup()"); But it
    work fine if all reside on the same domain,eg( (A) html page load
    flash file form (A)). Anyone know how to solve this other than
    create a set of flash files on (B).
    Regards,
    Raymond

    http://livedocs.adobe.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?cont ext=Flash_MX_2004&file=00001750.html

  • Calling JavaScript from rangeChangeListener

    Hi,
    I can not call javaScript function from my rangeChangeListener attribute on my table. Is there a way to call JS somehow?
    My situation is following:
    I have table with tableSelectMany. I am condittionaly rendering tableSelectMany checkboxes.
    Sometimes I have no checkboxes in current page (but there is checkboxes in other pages).
    The problem is that Select all and Select none functionalities (that comes automaticaly with tableSelectMany) are not disabled for that kind of pages, so I get error when trying to select when theres nothing in the page to select.
    So I need javascript on rangeChangeListener event to check if I have checkboxes and if not - disable them.
    It looks like ADF bug. Maybe somebody had the same sort of problem or have ideas on how to handle this situation?

    Hi,
    in this case you either go for a terrible JavaScript hack, or get rid of it alltogether
        <afh:head title="DepartmentsTable">
                <style type="text/css">
                    .x2l {display:none;}
                </style>
        </afh:head>Frank

  • Java calling JavaScript

    I have a peculiar problem. ..
    i need to call a javascript function from jsp and get the string value returned by the function...
    i am calling the function like this
    <BODY BGCOLOR="#FDF5E6" onload="respPrompt('<%=line%>')"> in jsp file
    here is the function..
    script language="JavaScript">
    function respPrompt(line) {
    alert("hello")
    var favorite = prompt('Edit the line?',line);
    if (favorite) alert("edited line is s: " + favorite);
    else alert("You pressed Cancel or no value was entered!");
    return favorite;
    </script>
    i need to get hold of the value "favorite" in the jsp programm...and need to write it to a file...am doing this since i cannot handle files from inside a javascript function....
    plz gimme ur suggestions..
    thanks
    rao

    Java runs on the server
    javascript runs on the client in the web-browser.
    The only communication between the two is via http.
    You send a request (with request parameters)
    You receive a response in the form of an HTML page.
    Thats all the communication there is.
    Java can't call javascript, and javascript can't call java.
    If you need to prompt the user for info, send back an html page asking for that info, and then have them submit that result back to another servlet/jsp
    Cheers,
    evnafets

  • Calling Javascript by ExternalInterface advances playhead?

    HI,
    I'd like to call Javascript function by ExternalInterface while a flash movie is playing. I actually could call a function but the movie looked faster than the expected framerate. It looked like the playhead advanced everytime I called the function.
    After some trials, it seems like...
    Playheads in all MovieClips advances when I call Javascript function by  ExternalInterface.call().
    The playhead advances only while the movie clip is playing. Once it is  stopped, it'll not be advanced until it is played again.
    I made an simple example and attached it to this post so that you can see what I mean.
    The attached file contains an fla file which counts up number from 1 to 5 and is played at 0.5 fps, that is, moves to the next frame every 2 seconds. And there is a button titled "Call JS" which calls a blank Javascript function, which does nothing. If you open the html file, you'll see the number counted up slowly but advanced by one or two frames when you click the button.
    Please look at the first frame of 'action' layer and the js file, if you'd like to see what I did for this with ActionScript and Javascript. You'll see the number not counted up even when you click the button, as I  mentioned above, if you add stop(); at the end of the AS code.
    I'm using Flash CS4 on Mac OS X 10.6. The web browsers are Safari 4.0.4 and Firefox 3.6, and the version of flash player is MAC 10.0.45.2.
    I wonder I'm doing anything wrong or this is the way I shouldn't do. Has  anyone experienced something like this?
    Any help will be much appreciated. Thanks in advance.

    i don't see a problem except the op seems confused.  i'm not sure why (or even if) he expects the playhead to stop when there's no code to stop it.
    anyway,
    1.  the attached files contain no stop().  once added, the playhead stops, as expected.
    2.  there's no doNothing js function.  once added, it executes, as expected.
    3.  the attached files behave, as expected.

Maybe you are looking for

  • Dragging an HTML component

    Hello, I'm a bit of a  newbie to Flex ( started Yesterday ) and i'm finding my way quit well. Using some of the examples that the internet provides i managed to create the following applcation: <?xml version="1.0" encoding="utf-8"?> <s:WindowedApplic

  • How do I download Elements 11 to a new laptop?

    I have Elements 11 on my desktop and an old laptop.  I know I have to deactivate the laptop before downloading to my new laptop, but how do I download Elements 11?  I have the activation code from my previous purchase.

  • Condition of Gnome Shell (git) and its issues

    I had recently been able to build gnome-shell-git succesfully, but, after that, there have always been issues. I have uploaded gnome-shell-git on AUR http://aur.archlinux.org/packages.php?ID=29509, but it seems that there are some things that may be

  • Availability quanity for Assembly order.. ??

    Hi experts, where is the settings for availability quanity for assembly order.. problem is.. after creating sales order  when we wanted to do change ..that time i am not getting availability quantity.. Thanksin Advance, Anthyodaya... Edited by: anthy

  • Why can i not play music out loud on the iphone 5

    I have just got my iphone 5, it allowed me to play musci out aloud at first, and now it will only play through head phones, any ideas