Javascript and flex

Javascript and flex

Hi.....

How do you call javascript from Flex?

Give the right example.


Thanks
View Answers

October 15, 2010 at 1:23 PM

Ans: Using the ExternalInterface API to access JavaScript from Flex. In flex application, you may have called function defined in action script. Sometimes you may need to call a javascript function defined in html file where your flex file is embed. For this purpose, ExternalInterface api is used which makes it possible to communicate between ActionScript and flash player container like html.

for example: The MXML file are following

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">;
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.external.*;
public var _brandProduct1:Object = {brand: "Sony", product: "Sony Bravia S Series LCD TV, KLV-26S400A", price: "Rs.34,900"};
public var _brandProduct2:Object = {brand: "Sony", product: "Sony Bravia S Series LCD TV, KLV-40S310A", price: "Rs.77,990"};
private function callJS(brandProduct:Object):void {
if (ExternalInterface.available){
ExternalInterface.call("displayBrandProduct", brandProduct);
}else {
Alert.show("Failed.");
}
}
]]>
</mx:Script>
<mx:Button label="Get 1st Product Info" click="callJS(_brandProduct1)"/>
<mx:Button label="Get 2nd Product Info" click="callJS(_brandProduct2)"/>
</mx:Application>

The java Script file are following:

<script language="javascript">
function displayBrandProduct(brandProduct){
if(brandProduct != null){
alert("Brand: "+brandProduct.brand+"\nProduct: "+brandProduct.product+"\nPrice: "+brandProduct.price);
}else{
alert("Please select a person, or maybe I screwed up.");
}
}
</script>









Related Tutorials/Questions & Answers:
Javascript and flex
Javascript and flex  Hi..... How do you call javascript from Flex... the ExternalInterface API to access JavaScript from Flex. In flex application, you may have called function defined in action script. Sometimes you may need to call a javascript
how to call javascript function from flex
how to call javascript function from flex  how to call javascript function from flex
Advertisements
Flex - Call JavaScript Function And Open a Popup Window that Displays Data
Flex - Call JavaScript Function And Open a Popup Window that Displays Data  Flex - Call JavaScript Function And Open a Popup Window that Displays Data
Calling Flex Function From JavaScript
From JavaScript Sometimes, you may need to call flex function from JavaScript... by JavaScript to call the flex function, and the second parameter is the actual... </mx:Application> To Call Flex method from JavaScript do
Calling Anonymous JavaScript Function From Flex
: #FFFFCC; } Calling Anonymous JavaScript Function From Flex In flex application, you can call javascript function defined in html file where your flex file is embed. But you can also call an anomymous javascript function
JavaScript call from flex application
; } A JavaScript call from flex application In flex application, you may... a javascript function defined in html file where your flex file is embed.... in html or not. The call() method is used to call the javascript function
JavaScript
JavaScript  clone JavaScript
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
JavaScript
JavaScript  how to get full path of a file type in javascript
javascript
javascript  Hi deepak, how to write form validation on javascript
javascript
javascript  write a program to display implement about browsers using javascript
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
javascript
javascript  i have just learned javascript... can you tell me what kind of applications can be made by javascript?? thank you
Flex Looping
Flex Looping  I need example for flex looping mechanisam example
Flex - Framework
Flex  database conectivity in flex
javascript
javascript  how to set the request or session attribute in javascript head part of jsp page
javascript
javascript  Hi sir, This is sinduri, i want to learn javascript, so plz can u help me.how to learn
javascript
javascript  hi sir, if i want to learn javascript. what concepts i want to know
Sitemap Adobe Flex Tutorial
Introducing Flex | Downloading and Installing Flex | Downloading and Installing Flex Builder | Compiling MXML application | Eclipse flex ant coding | Compiling MXML files with FlexBuilder | Flex Combo Box
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Javascript
Javascript   Javascript to check Numeric entry in checkbox.....   Hi Please find the following code for numeric entry validation in javascript function validateBox(){ var data=document.myForm.someText.value
Flex Combobox
Flex Combobox  flex combobox with database as dataprovider   You can visit the following link for detailed tutorial on the topic. May this will be helpful to you. http://www.roseindia.net/flex/flex-combo-box.shtml
javascript
javascript  hi, I was actually working on to calculate the number of days between two dates of yyyy-mm-dd format using javascript, and when i click on button then number of days should be display in textbox
javaScript
javaScript  . Print a table like below in JAVASCRIPT 5 x 1 = 5 5 x 2 = 10 ΓΆβ?¬Β¦ΓΆβ?¬Β¦ΓΆβ?¬Β¦. 5 x 20 = 100
javascript
javascript  passing javascript values to jsp   Hi Friend, Try the following code:ADS_TO_REPLACE_1 form.jsp: <html> <script>... Javascript value In JSP"> <% String st=request.getParameter("msg"); if(st
Javascript
this format xxx-xxx-xxxx, i want the code in javascript. as a function.   Javascript Phone Number Validation <html> <script> function..." method="post" onsubmit="javascript:return validate();"> Phone Number:<
Flex basic
Flex basic  Hi...... please just tell me about Can we run Flex applications in MAC? Thanks
Flex and Java
Flex and Java  hi..... Please give similiarities between Java and Flex. Thanks
Flex event
Flex event  Hi.... Please tell me about How to create your own event in flex? Thanks
Javascript
Javascript  Dear Sir, Thank You a lot for your continuos support.Again i am in need of your help. What is the javascript code to disable a link,once... javascript or css Please help me.Urgent Regards Debasis   Hello Friend
Flex and Java
Flex and Java  Hi...... Give the name of Collection which can be mapped to java and Flex and vice-versa. please give the name of all collections which is used in flex and java.. Thanks
Flex and Java
Flex and Java  Hi.... What are the config files that are used to connect Java and Flex applications? Please provide the solution of this prob so i connect java and flex.... Thanks
Flex as a Service
Flex as a Service  Hi....... just tell me about How do I run Flex as a service? please give me an example if possible Thanks  Ans: Flex is not a server. It is the pert of your web application. you can use
Flex Updates
Flex Updates  Sir, first Thanks For Good Resource for Every One! i am New to Flex... but,in Current Updates Tell Us Flex Becomes To down!(Sorry To say).. May I know Future groom & Advantage of Flex Over Other Web
Javascript
Javascript  <html> <head> <script type="text/javascript"> function validateForm() { var sname=document.getElementById('spocname'); var scontact=document.getElementById('spoccontact'); if(sname.value.length
Flex basic
Flex basic  Hi.......... I want to know about What is localToGlobal and globalToLocal in flex? please give me ans ASAP..... Thanks
Flex application
Flex application  Hi..... What kind of applications you can create from flex? please give the name of these applications....... Thanks
Flex basic
Flex basic  Hi.... can you tell me about Is Flex OS specific or operating system independent? please give the description about it....... Thanks
Flex basic
Flex basic  Hi.... I want to know Do we need any plugins to run Flex applications? please give the ans ASAP....... Thanks
Resize browser in flex
Resize browser in flex  Hi........ Please tell me about How can I Resize the Internet Explorer browser window from flex ? please give me... with JavaScript in the HTML wrapper: getURL('javascript:window.resizeTo(900,900
Flex difference
Flex difference  Hi.... please tell me about What is the difference between Flex 2.0 and Flex 3.0? Thanks  Ans: There are some advantages of Flex3.0 over Flex 2.0 they are following: 1. Faster compilation time
javascript
javascript
javascript  how to create random question using javascript?   <html> <script> function displayQuestions() { document.getElementById("text").value=" "; var Questions = new Array(20
javascript
Adding a flex table in another flex table column
Adding a flex table in another flex table column  how to add a flex table in another flex table column
javascript
javascript  Hi deepak, sample example on javascript form validation   <html> <script> function checkName(text) { if(isNaN(text)){ return 1; } else{ alert("Please enter a valid name. The only charachters
Flex basic
Flex basic  Hi.... Can flex application communicate with each other on the client? please give me the answer ASAP.....ADS_TO_REPLACE_1 Thanks   Ans: See the LocalConnection API In the flex documentation. ADS
Flex with JSP
Flex with JSP  i want to draw chart in jsp page using flex. how can i do that? any solution??   Flex charts You can visit the following links: http://www.roseindia.net/tutorial/flex/flex4/components/charteffect.html

Ads