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
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 8Eggbertx, 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. -
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 PatelFound 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, -
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 -
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
JoeSo, 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 -
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. -
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,
VIDsYou 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. -
Hi, I am working on Labview 8.0.
I am trying to communicate to a thrid party HW using the driver file he has provided to me.
The drive file is a *.lib file.
I am unable to call the function from the lib file.
I could get only from a DLL.
Pls help .
Regards
-Patilpatil wrote:
When it is possible in Lab Windows, why calling a function from a static library is prohibited?
I was trying to use Function node, but found that it is only for functions from a DLL file.
Will CIN be useful.?
LabWindows is not the same as LabVIEW. LabVIEW cannot call .lib files. LIB files are intermediary products and you need to use a wrapper DLL that's compatible with the object format of the .lib file. It's as simple as that. LabWindows creates C application and from that perspective is no different than a regular C
compiler. That's why you can call .lib files because that's how .lib
files are used.
A CIN, as pointed out, is something completely different and will not help you. -
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,
SherlynI 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). -
Calling c function from java!!
hi all,
I want to call c function from java . I have gone through the link http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html for JNI.
According to this link we need to write the native method implementation in such a way that the method signature should exactly match the method signature created in the header file.
My problem is that i have a c application which i cannot modify in any ways i.e., i cannot change its code. But i want to call its function from my java code.
Please suggest me appropriate solution for this. Please let me know whether it can be done using JNI or is there any other method for this.
thanksThis link is amazing since those sources were wrote in 1998 and I started to develop JNative in 2004. I did not found them when I started.
Since JNative can deal with callbacks and probably COM in a near future, I expect to see it living to Dolphin at least.
--Marc (http://jnative.sf.net) -
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.
AntonioHi 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. -
I have two IPhones and one IPad all with the same Apple ID. I can call facetime between the two IPhones, but I cannot call the IPAD from either of the IPhones and when I call my IPhone from the IPad it rings my wife's IPhone after briefly calling mine.
Each device needs a separate address. Use an email address (gmail.com) on the iPad.
Using FaceTime http://support.apple.com/kb/ht4319
Troubleshooting FaceTime http://support.apple.com/kb/TS3367
The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
http://tinyurl.com/a7odey8
Troubleshooting FaceTime and iMessage activation
http://support.apple.com/kb/TS4268
Using FaceTime and iMessage behind a firewall
http://support.apple.com/kb/HT4245
iOS: About Messages
http://support.apple.com/kb/HT3529
Set up iMessage
http://www.apple.com/ca/ios/messages/
Troubleshooting Messages
http://support.apple.com/kb/TS2755
Setting Up Multiple iOS Devices for iMessage and Facetime
http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
FaceTime and iMessage not accepting Apple ID password
http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
Unable to use FaceTime and iMessage with my apple ID
https://discussions.apple.com/thread/4649373?tstart=90
For non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
How to Send SMS from iPad
http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
Cheers, Tom -
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?
Thanksor refer this theread....calling function from procedure
Maybe you are looking for
-
HT1577 how do i download purchases from the itune store on my computer to my ipod
how do i download itune purchases from the computer to my ipod?
-
Hello, We are using wls 10.3.3 located in different unix machine. Using putty we work with the servers from the desktop computers. We want to monitor the JVM using Jrockit mission control from desktop. We have JRMC installed in the Windows XP desktop
-
Playing Clips/Sequences in background, while using other application?
I am working for a reality TV show and we are trying to take notes in Microsoft Word while the editors sequences are playing. Is there any way to change the preferences so that Final Cut will play a clip or a sequence while we are using another appli
-
Ram errors seemingly caused by bumps
I bought a Macbook Pro at the start of the semester. I put some extra ram in it right away, but a few weeks later I opened it up after putting it to sleep to find it A shut down and B beeping every time I turned it on. I took the ram out and put it b
-
Maximum number of MRAS requests / allocations per user?
Hello, I have a test C++ SIP application that registers to a Lync edge server and is able to perform MRAS requests to it. The MRAS responses allow me to create TURN allocations on the TURN component of the edge server. However, I seem to be hitting a